@@ -54,6 +54,7 @@ extern crate clippy_utils;
54
54
use clippy_utils:: parse_msrv;
55
55
use rustc_data_structures:: fx:: FxHashSet ;
56
56
use rustc_lint:: LintId ;
57
+ use rustc_semver:: RustcVersion ;
57
58
use rustc_session:: Session ;
58
59
59
60
/// Macro used to declare a Clippy lint.
@@ -448,6 +449,39 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se
448
449
store. register_pre_expansion_pass ( move || Box :: new ( attrs:: EarlyAttributes { msrv } ) ) ;
449
450
}
450
451
452
+ fn read_msrv ( conf : & Conf , sess : & Session ) -> Option < RustcVersion > {
453
+ let cargo_msrv = std:: env:: var ( "CARGO_PKG_RUST_VERSION" )
454
+ . ok ( )
455
+ . and_then ( |v| parse_msrv ( & v, None , None ) ) ;
456
+ let clippy_msrv = conf. msrv . as_ref ( ) . and_then ( |s| {
457
+ parse_msrv ( s, None , None ) . or_else ( || {
458
+ sess. err ( & format ! (
459
+ "error reading Clippy's configuration file. `{}` is not a valid Rust version" ,
460
+ s
461
+ ) ) ;
462
+ None
463
+ } )
464
+ } ) ;
465
+
466
+ if let Some ( cargo_msrv) = cargo_msrv {
467
+ if let Some ( clippy_msrv) = clippy_msrv {
468
+ // if both files have an msrv, let's compare them and emit a warning if they differ
469
+ if clippy_msrv != cargo_msrv {
470
+ sess. warn ( & format ! (
471
+ "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{}`" ,
472
+ clippy_msrv
473
+ ) ) ;
474
+ }
475
+
476
+ Some ( clippy_msrv)
477
+ } else {
478
+ Some ( cargo_msrv)
479
+ }
480
+ } else {
481
+ clippy_msrv
482
+ }
483
+ }
484
+
451
485
#[ doc( hidden) ]
452
486
pub fn read_conf ( sess : & Session ) -> Conf {
453
487
let file_name = match utils:: conf:: lookup_conf_file ( ) {
@@ -463,12 +497,11 @@ pub fn read_conf(sess: &Session) -> Conf {
463
497
let TryConf { conf, errors } = utils:: conf:: read ( & file_name) ;
464
498
// all conf errors are non-fatal, we just use the default conf in case of error
465
499
for error in errors {
466
- sess. struct_err ( & format ! (
500
+ sess. err ( & format ! (
467
501
"error reading Clippy's configuration file `{}`: {}" ,
468
502
file_name. display( ) ,
469
503
format_error( error)
470
- ) )
471
- . emit ( ) ;
504
+ ) ) ;
472
505
}
473
506
474
507
conf
@@ -575,16 +608,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
575
608
store. register_late_pass ( || Box :: new ( non_octal_unix_permissions:: NonOctalUnixPermissions ) ) ;
576
609
store. register_early_pass ( || Box :: new ( unnecessary_self_imports:: UnnecessarySelfImports ) ) ;
577
610
578
- let msrv = conf. msrv . as_ref ( ) . and_then ( |s| {
579
- parse_msrv ( s, None , None ) . or_else ( || {
580
- sess. err ( & format ! (
581
- "error reading Clippy's configuration file. `{}` is not a valid Rust version" ,
582
- s
583
- ) ) ;
584
- None
585
- } )
586
- } ) ;
587
-
611
+ let msrv = read_msrv ( conf, sess) ;
588
612
let avoid_breaking_exported_api = conf. avoid_breaking_exported_api ;
589
613
let allow_expect_in_tests = conf. allow_expect_in_tests ;
590
614
let allow_unwrap_in_tests = conf. allow_unwrap_in_tests ;
0 commit comments