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