@@ -51,7 +51,7 @@ use log::{debug, trace, warn};
5151use rustfix:: diagnostics:: Diagnostic ;
5252use rustfix:: { self , CodeFix } ;
5353
54- use crate :: core:: compiler:: RustcTargetData ;
54+ use crate :: core:: compiler:: { CompileKind , RustcTargetData , TargetInfo } ;
5555use crate :: core:: resolver:: features:: { DiffMap , FeatureOpts , FeatureResolver } ;
5656use crate :: core:: resolver:: { HasDevUnits , Resolve , ResolveBehavior } ;
5757use crate :: core:: { Edition , MaybePackage , Workspace } ;
@@ -67,6 +67,7 @@ const FIX_ENV: &str = "__CARGO_FIX_PLZ";
6767const BROKEN_CODE_ENV : & str = "__CARGO_FIX_BROKEN_CODE" ;
6868const EDITION_ENV : & str = "__CARGO_FIX_EDITION" ;
6969const IDIOMS_ENV : & str = "__CARGO_FIX_IDIOMS" ;
70+ const SUPPORTS_FORCE_WARN : & str = "__CARGO_SUPPORTS_FORCE_WARN" ;
7071
7172pub struct FixOptions {
7273 pub edition : bool ,
@@ -122,6 +123,17 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions) -> CargoResult<()> {
122123 let rustc = ws. config ( ) . load_global_rustc ( Some ( ws) ) ?;
123124 wrapper. arg ( & rustc. path ) ;
124125
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+
125137 // primary crates are compiled using a cargo subprocess to do extra work of applying fixes and
126138 // repeating build until there are no more changes to be applied
127139 opts. compile_opts . build_config . primary_unit_rustc = Some ( wrapper) ;
@@ -362,7 +374,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
362374 // that we have to back it all out.
363375 if !fixes. files . is_empty ( ) {
364376 let mut cmd = rustc. build_command ( ) ;
365- args. apply ( & mut cmd, config ) ;
377+ args. apply ( & mut cmd) ;
366378 cmd. arg ( "--error-format=json" ) ;
367379 debug ! ( "calling rustc for final verification: {:?}" , cmd) ;
368380 let output = cmd. output ( ) . context ( "failed to spawn rustc" ) ?;
@@ -403,7 +415,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
403415 // - If `--broken-code`, show the error messages.
404416 // - If the fix succeeded, show any remaining warnings.
405417 let mut cmd = rustc. build_command ( ) ;
406- args. apply ( & mut cmd, config ) ;
418+ args. apply ( & mut cmd) ;
407419 for arg in args. format_args {
408420 // Add any json/error format arguments that Cargo wants. This allows
409421 // things like colored output to work correctly.
@@ -497,7 +509,7 @@ fn rustfix_crate(
497509 // We'll generate new errors below.
498510 file. errors_applying_fixes . clear ( ) ;
499511 }
500- rustfix_and_fix ( & mut fixes, rustc, filename, args, config ) ?;
512+ rustfix_and_fix ( & mut fixes, rustc, filename, args) ?;
501513 let mut progress_yet_to_be_made = false ;
502514 for ( path, file) in fixes. files . iter_mut ( ) {
503515 if file. errors_applying_fixes . is_empty ( ) {
@@ -539,15 +551,14 @@ fn rustfix_and_fix(
539551 rustc : & ProcessBuilder ,
540552 filename : & Path ,
541553 args : & FixArgs ,
542- config : & Config ,
543554) -> Result < ( ) , Error > {
544555 // If not empty, filter by these lints.
545556 // TODO: implement a way to specify this.
546557 let only = HashSet :: new ( ) ;
547558
548559 let mut cmd = rustc. build_command ( ) ;
549560 cmd. arg ( "--error-format=json" ) ;
550- args. apply ( & mut cmd, config ) ;
561+ args. apply ( & mut cmd) ;
551562 debug ! (
552563 "calling rustc to collect suggestions and validate previous fixes: {:?}" ,
553564 cmd
@@ -822,10 +833,10 @@ impl FixArgs {
822833 } )
823834 }
824835
825- fn apply ( & self , cmd : & mut Command , config : & Config ) {
836+ fn apply ( & self , cmd : & mut Command ) {
826837 cmd. arg ( & self . file ) ;
827838 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 ( ) {
829840 // When migrating an edition, we don't want to fix other lints as
830841 // they can sometimes add suggestions that fail to apply, causing
831842 // the entire migration to fail. But those lints aren't needed to
@@ -844,7 +855,7 @@ impl FixArgs {
844855
845856 if let Some ( edition) = self . prepare_for_edition {
846857 if edition. supports_compat_lint ( ) {
847- if config . nightly_features_allowed {
858+ if env :: var_os ( SUPPORTS_FORCE_WARN ) . is_some ( ) {
848859 cmd. arg ( "--force-warn" )
849860 . arg ( format ! ( "rust-{}-compatibility" , edition) )
850861 . arg ( "-Zunstable-options" ) ;
0 commit comments