File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ extern crate rustc_typeck;
50
50
#[ macro_use]
51
51
extern crate clippy_utils;
52
52
53
+ use cargo_metadata:: MetadataCommand ;
53
54
use clippy_utils:: parse_msrv;
54
55
use rustc_data_structures:: fx:: FxHashSet ;
55
56
use rustc_lint:: LintId ;
@@ -455,7 +456,7 @@ pub fn read_conf(sess: &Session) -> Conf {
455
456
} ,
456
457
} ;
457
458
458
- let TryConf { conf, errors } = utils:: conf:: read ( & file_name) ;
459
+ let TryConf { mut conf, errors } = utils:: conf:: read ( & file_name) ;
459
460
// all conf errors are non-fatal, we just use the default conf in case of error
460
461
for error in errors {
461
462
sess. struct_err ( & format ! (
@@ -466,6 +467,23 @@ pub fn read_conf(sess: &Session) -> Conf {
466
467
. emit ( ) ;
467
468
}
468
469
470
+ if conf. msrv . is_none ( ) {
471
+ // let's try to get msrv from `Cargo.toml`s field `rust-version`
472
+ match MetadataCommand :: new ( ) . no_deps ( ) . exec ( ) {
473
+ Ok ( metadata) => {
474
+ conf. msrv = metadata
475
+ . packages
476
+ . get ( 0 )
477
+ . and_then ( |x| x. rust_version . as_ref ( ) )
478
+ . and_then ( |r| r. comparators . get ( 0 ) )
479
+ . map ( |v| format ! ( "{}.{}.{}" , v. major, v. minor. unwrap_or( 0 ) , v. patch. unwrap_or( 0 ) ) ) ;
480
+ } ,
481
+ Err ( e) => {
482
+ sess. struct_err ( & format ! ( "could not read cargo metadata: {}" , e) ) . emit ( ) ;
483
+ } ,
484
+ }
485
+ }
486
+
469
487
conf
470
488
}
471
489
You can’t perform that action at this time.
0 commit comments