@@ -51,7 +51,7 @@ use log::{debug, trace, warn};
51
51
use rustfix:: diagnostics:: Diagnostic ;
52
52
use rustfix:: { self , CodeFix } ;
53
53
54
- use crate :: core:: compiler:: RustcTargetData ;
54
+ use crate :: core:: compiler:: { CompileKind , RustcTargetData , TargetInfo } ;
55
55
use crate :: core:: resolver:: features:: { DiffMap , FeatureOpts , FeatureResolver } ;
56
56
use crate :: core:: resolver:: { HasDevUnits , Resolve , ResolveBehavior } ;
57
57
use crate :: core:: { Edition , MaybePackage , Workspace } ;
@@ -67,6 +67,7 @@ const FIX_ENV: &str = "__CARGO_FIX_PLZ";
67
67
const BROKEN_CODE_ENV : & str = "__CARGO_FIX_BROKEN_CODE" ;
68
68
const EDITION_ENV : & str = "__CARGO_FIX_EDITION" ;
69
69
const IDIOMS_ENV : & str = "__CARGO_FIX_IDIOMS" ;
70
+ const SUPPORTS_FORCE_WARN : & str = "__CARGO_SUPPORTS_FORCE_WARN" ;
70
71
71
72
pub struct FixOptions {
72
73
pub edition : bool ,
@@ -122,6 +123,17 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions) -> CargoResult<()> {
122
123
let rustc = ws. config ( ) . load_global_rustc ( Some ( ws) ) ?;
123
124
wrapper. arg ( & rustc. path ) ;
124
125
126
+ // Remove this once 1.56 is stabilized.
127
+ let target_info = TargetInfo :: new (
128
+ ws. config ( ) ,
129
+ & opts. compile_opts . build_config . requested_kinds ,
130
+ & rustc,
131
+ CompileKind :: Host ,
132
+ ) ?;
133
+ if target_info. supports_force_warn {
134
+ wrapper. env ( SUPPORTS_FORCE_WARN , "1" ) ;
135
+ }
136
+
125
137
// primary crates are compiled using a cargo subprocess to do extra work of applying fixes and
126
138
// repeating build until there are no more changes to be applied
127
139
opts. compile_opts . build_config . primary_unit_rustc = Some ( wrapper) ;
@@ -362,7 +374,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
362
374
// that we have to back it all out.
363
375
if !fixes. files . is_empty ( ) {
364
376
let mut cmd = rustc. build_command ( ) ;
365
- args. apply ( & mut cmd, config ) ;
377
+ args. apply ( & mut cmd) ;
366
378
cmd. arg ( "--error-format=json" ) ;
367
379
debug ! ( "calling rustc for final verification: {:?}" , cmd) ;
368
380
let output = cmd. output ( ) . context ( "failed to spawn rustc" ) ?;
@@ -403,7 +415,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
403
415
// - If `--broken-code`, show the error messages.
404
416
// - If the fix succeeded, show any remaining warnings.
405
417
let mut cmd = rustc. build_command ( ) ;
406
- args. apply ( & mut cmd, config ) ;
418
+ args. apply ( & mut cmd) ;
407
419
for arg in args. format_args {
408
420
// Add any json/error format arguments that Cargo wants. This allows
409
421
// things like colored output to work correctly.
@@ -497,7 +509,7 @@ fn rustfix_crate(
497
509
// We'll generate new errors below.
498
510
file. errors_applying_fixes . clear ( ) ;
499
511
}
500
- rustfix_and_fix ( & mut fixes, rustc, filename, args, config ) ?;
512
+ rustfix_and_fix ( & mut fixes, rustc, filename, args) ?;
501
513
let mut progress_yet_to_be_made = false ;
502
514
for ( path, file) in fixes. files . iter_mut ( ) {
503
515
if file. errors_applying_fixes . is_empty ( ) {
@@ -539,15 +551,14 @@ fn rustfix_and_fix(
539
551
rustc : & ProcessBuilder ,
540
552
filename : & Path ,
541
553
args : & FixArgs ,
542
- config : & Config ,
543
554
) -> Result < ( ) , Error > {
544
555
// If not empty, filter by these lints.
545
556
// TODO: implement a way to specify this.
546
557
let only = HashSet :: new ( ) ;
547
558
548
559
let mut cmd = rustc. build_command ( ) ;
549
560
cmd. arg ( "--error-format=json" ) ;
550
- args. apply ( & mut cmd, config ) ;
561
+ args. apply ( & mut cmd) ;
551
562
debug ! (
552
563
"calling rustc to collect suggestions and validate previous fixes: {:?}" ,
553
564
cmd
@@ -822,10 +833,10 @@ impl FixArgs {
822
833
} )
823
834
}
824
835
825
- fn apply ( & self , cmd : & mut Command , config : & Config ) {
836
+ fn apply ( & self , cmd : & mut Command ) {
826
837
cmd. arg ( & self . file ) ;
827
838
cmd. args ( & self . other ) ;
828
- if self . prepare_for_edition . is_some ( ) && config . nightly_features_allowed {
839
+ if self . prepare_for_edition . is_some ( ) && env :: var_os ( SUPPORTS_FORCE_WARN ) . is_some ( ) {
829
840
// When migrating an edition, we don't want to fix other lints as
830
841
// they can sometimes add suggestions that fail to apply, causing
831
842
// the entire migration to fail. But those lints aren't needed to
@@ -844,7 +855,7 @@ impl FixArgs {
844
855
845
856
if let Some ( edition) = self . prepare_for_edition {
846
857
if edition. supports_compat_lint ( ) {
847
- if config . nightly_features_allowed {
858
+ if env :: var_os ( SUPPORTS_FORCE_WARN ) . is_some ( ) {
848
859
cmd. arg ( "--force-warn" )
849
860
. arg ( format ! ( "rust-{}-compatibility" , edition) )
850
861
. arg ( "-Zunstable-options" ) ;
0 commit comments