@@ -106,12 +106,12 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
106106 eprintln ! ( "Warning: clippy-driver not found: {:?}" , e) ;
107107 }
108108
109- opts. compile_opts . build_config . primary_unit_rustc = Some ( util:: config:: clippy_driver ( ) ) ;
109+ let clippy_args = opts
110+ . clippy_args
111+ . as_ref ( )
112+ . map_or_else ( String :: new, |args| serde_json:: to_string ( & args) . unwrap ( ) ) ;
110113
111- if let Some ( clippy_args) = & opts. clippy_args {
112- let clippy_args = serde_json:: to_string ( & clippy_args) . unwrap ( ) ;
113- wrapper. env ( CLIPPY_FIX_ARGS , clippy_args) ;
114- }
114+ wrapper. env ( CLIPPY_FIX_ARGS , clippy_args) ;
115115 }
116116
117117 * opts
@@ -130,7 +130,9 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
130130 server. configure ( & mut wrapper) ;
131131 }
132132
133- opts. compile_opts . build_config . rustc_wrapper = Some ( wrapper) ;
133+ // primary crates are compiled using a cargo subprocess to do extra work of applying fixes and
134+ // repeating build until there are no more changes to be applied
135+ opts. compile_opts . build_config . primary_unit_rustc = Some ( wrapper) ;
134136
135137 ops:: compile ( ws, & opts. compile_opts ) ?;
136138 Ok ( ( ) )
@@ -219,18 +221,10 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
219221 trace ! ( "cargo-fix as rustc got file {:?}" , args. file) ;
220222 let rustc = args. rustc . as_ref ( ) . expect ( "fix wrapper rustc was not set" ) ;
221223
222- // Our goal is to fix only the crates that the end user is interested in.
223- // That's very likely to only mean the crates in the workspace the user is
224- // working on, not random crates.io crates.
225- //
226- // The master cargo process tells us whether or not this is a "primary"
227- // crate via the CARGO_PRIMARY_PACKAGE environment variable.
228224 let mut fixes = FixedCrate :: default ( ) ;
229225 if let Some ( path) = & args. file {
230- if args. primary_package {
231- trace ! ( "start rustfixing {:?}" , path) ;
232- fixes = rustfix_crate ( & lock_addr, rustc. as_ref ( ) , path, & args) ?;
233- }
226+ trace ! ( "start rustfixing {:?}" , path) ;
227+ fixes = rustfix_crate ( & lock_addr, rustc. as_ref ( ) , path, & args) ?;
234228 }
235229
236230 // Ok now we have our final goal of testing out the changes that we applied.
@@ -279,7 +273,6 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
279273 }
280274
281275 // This final fall-through handles multiple cases;
282- // - Non-primary crates, which need to be built.
283276 // - If the fix failed, show the original warnings and suggestions.
284277 // - If `--broken-code`, show the error messages.
285278 // - If the fix succeeded, show any remaining warnings.
@@ -589,7 +582,6 @@ struct FixArgs {
589582 idioms : bool ,
590583 enabled_edition : Option < String > ,
591584 other : Vec < OsString > ,
592- primary_package : bool ,
593585 rustc : Option < PathBuf > ,
594586 clippy_args : Vec < String > ,
595587}
@@ -609,10 +601,12 @@ impl Default for PrepareFor {
609601impl FixArgs {
610602 fn get ( ) -> FixArgs {
611603 let mut ret = FixArgs :: default ( ) ;
612- ret. rustc = env:: args_os ( ) . nth ( 1 ) . map ( PathBuf :: from) ;
613604
614605 if let Ok ( clippy_args) = env:: var ( CLIPPY_FIX_ARGS ) {
615606 ret. clippy_args = serde_json:: from_str ( & clippy_args) . unwrap ( ) ;
607+ ret. rustc = Some ( util:: config:: clippy_driver ( ) ) ;
608+ } else {
609+ ret. rustc = env:: args_os ( ) . nth ( 1 ) . map ( PathBuf :: from) ;
616610 }
617611
618612 for arg in env:: args_os ( ) . skip ( 2 ) {
@@ -642,7 +636,6 @@ impl FixArgs {
642636 }
643637
644638 ret. idioms = env:: var ( IDIOMS_ENV ) . is_ok ( ) ;
645- ret. primary_package = env:: var ( "CARGO_PRIMARY_PACKAGE" ) . is_ok ( ) ;
646639 ret
647640 }
648641
@@ -658,14 +651,13 @@ impl FixArgs {
658651 cmd. args ( & self . other ) . arg ( "--cap-lints=warn" ) ;
659652 if let Some ( edition) = & self . enabled_edition {
660653 cmd. arg ( "--edition" ) . arg ( edition) ;
661- if self . idioms && self . primary_package && edition == "2018" {
654+ if self . idioms && edition == "2018" {
662655 cmd. arg ( "-Wrust-2018-idioms" ) ;
663656 }
664657 }
665- if self . primary_package {
666- if let Some ( edition) = self . prepare_for_edition_resolve ( ) {
667- cmd. arg ( "-W" ) . arg ( format ! ( "rust-{}-compatibility" , edition) ) ;
668- }
658+
659+ if let Some ( edition) = self . prepare_for_edition_resolve ( ) {
660+ cmd. arg ( "-W" ) . arg ( format ! ( "rust-{}-compatibility" , edition) ) ;
669661 }
670662 }
671663
0 commit comments