1
1
mod common_metadata;
2
2
mod feature_name;
3
3
mod lint_groups_priority;
4
+ mod missing_rust_version;
4
5
mod multiple_crate_versions;
5
6
mod wildcard_dependencies;
6
7
7
8
use cargo_metadata:: MetadataCommand ;
8
9
use clippy_config:: Conf ;
9
10
use clippy_utils:: diagnostics:: span_lint;
10
11
use clippy_utils:: is_lint_allowed;
12
+ use clippy_utils:: msrvs:: Msrv ;
11
13
use rustc_data_structures:: fx:: FxHashSet ;
12
14
use rustc_hir:: hir_id:: CRATE_HIR_ID ;
13
15
use rustc_lint:: { LateContext , LateLintPass , Lint } ;
@@ -213,9 +215,37 @@ declare_clippy_lint! {
213
215
"a lint group in `Cargo.toml` at the same priority as a lint"
214
216
}
215
217
218
+ declare_clippy_lint ! {
219
+ /// ### What it does
220
+ /// Checks to see if the `rust-version` field is defined in `Cargo.toml`.
221
+ ///
222
+ /// ### Why is this bad?
223
+ /// Starting with version 3, the [resolver] takes this field into account
224
+ /// when picking dependencies.
225
+ ///
226
+ /// ### Example
227
+ /// ```toml
228
+ /// [package]
229
+ /// # ...
230
+ /// ```
231
+ /// Use instead:
232
+ /// ```toml
233
+ /// [package]
234
+ /// # ...
235
+ /// rust-version = "1.84"
236
+ /// ```
237
+ ///
238
+ /// [resolver]: https://doc.rust-lang.org/cargo/reference/resolver.html#rust-version
239
+ #[ clippy:: version = "1.86.0" ]
240
+ pub MISSING_RUST_VERSION ,
241
+ cargo,
242
+ "the `rust-version` field is not defined in `Cargo.toml`"
243
+ }
244
+
216
245
pub struct Cargo {
217
246
allowed_duplicate_crates : FxHashSet < String > ,
218
247
ignore_publish : bool ,
248
+ msrv : Msrv ,
219
249
}
220
250
221
251
impl_lint_pass ! ( Cargo => [
@@ -225,13 +255,15 @@ impl_lint_pass!(Cargo => [
225
255
MULTIPLE_CRATE_VERSIONS ,
226
256
WILDCARD_DEPENDENCIES ,
227
257
LINT_GROUPS_PRIORITY ,
258
+ MISSING_RUST_VERSION ,
228
259
] ) ;
229
260
230
261
impl Cargo {
231
262
pub fn new ( conf : & ' static Conf ) -> Self {
232
263
Self {
233
264
allowed_duplicate_crates : conf. allowed_duplicate_crates . iter ( ) . cloned ( ) . collect ( ) ,
234
265
ignore_publish : conf. cargo_ignore_publish ,
266
+ msrv : conf. msrv . clone ( ) ,
235
267
}
236
268
}
237
269
}
@@ -243,6 +275,7 @@ impl LateLintPass<'_> for Cargo {
243
275
REDUNDANT_FEATURE_NAMES ,
244
276
NEGATIVE_FEATURE_NAMES ,
245
277
WILDCARD_DEPENDENCIES ,
278
+ MISSING_RUST_VERSION ,
246
279
] ;
247
280
static WITH_DEPS_LINTS : & [ & Lint ] = & [ MULTIPLE_CRATE_VERSIONS ] ;
248
281
@@ -256,6 +289,7 @@ impl LateLintPass<'_> for Cargo {
256
289
Ok ( metadata) => {
257
290
common_metadata:: check ( cx, & metadata, self . ignore_publish ) ;
258
291
feature_name:: check ( cx, & metadata) ;
292
+ missing_rust_version:: check ( cx, & metadata, & self . msrv ) ;
259
293
wildcard_dependencies:: check ( cx, & metadata) ;
260
294
} ,
261
295
Err ( e) => {
0 commit comments