@@ -56,7 +56,7 @@ use crate::core::Workspace;
5656use crate :: ops:: { self , CompileOptions } ;
5757use crate :: util:: diagnostic_server:: { Message , RustfixDiagnosticServer } ;
5858use crate :: util:: errors:: CargoResult ;
59- use crate :: util:: paths;
59+ use crate :: util:: { self , paths} ;
6060use crate :: util:: { existing_vcs_repo, LockServer , LockServerClient } ;
6161
6262const FIX_ENV : & str = "__CARGO_FIX_PLZ" ;
@@ -81,46 +81,31 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
8181
8282 // Spin up our lock server, which our subprocesses will use to synchronize fixes.
8383 let lock_server = LockServer :: new ( ) ?;
84- opts. compile_opts
85- . build_config
86- . extra_rustc_env
87- . push ( ( FIX_ENV . to_string ( ) , lock_server. addr ( ) . to_string ( ) ) ) ;
84+ let mut wrapper = util:: process ( env:: current_exe ( ) ?) ;
85+ wrapper. env ( FIX_ENV , lock_server. addr ( ) . to_string ( ) ) ;
8886 let _started = lock_server. start ( ) ?;
8987
9088 opts. compile_opts . build_config . force_rebuild = true ;
9189
9290 if opts. broken_code {
93- let key = BROKEN_CODE_ENV . to_string ( ) ;
94- opts. compile_opts
95- . build_config
96- . extra_rustc_env
97- . push ( ( key, "1" . to_string ( ) ) ) ;
91+ wrapper. env ( BROKEN_CODE_ENV , "1" ) ;
9892 }
9993
10094 if opts. edition {
101- let key = EDITION_ENV . to_string ( ) ;
102- opts. compile_opts
103- . build_config
104- . extra_rustc_env
105- . push ( ( key, "1" . to_string ( ) ) ) ;
95+ wrapper. env ( EDITION_ENV , "1" ) ;
10696 } else if let Some ( edition) = opts. prepare_for {
107- opts. compile_opts
108- . build_config
109- . extra_rustc_env
110- . push ( ( PREPARE_FOR_ENV . to_string ( ) , edition. to_string ( ) ) ) ;
97+ wrapper. env ( PREPARE_FOR_ENV , edition) ;
11198 }
11299 if opts. idioms {
113- opts. compile_opts
114- . build_config
115- . extra_rustc_env
116- . push ( ( IDIOMS_ENV . to_string ( ) , "1" . to_string ( ) ) ) ;
100+ wrapper. env ( IDIOMS_ENV , "1" ) ;
117101 }
118- opts . compile_opts . build_config . cargo_as_rustc_wrapper = true ;
102+
119103 * opts
120104 . compile_opts
121105 . build_config
122106 . rustfix_diagnostic_server
123107 . borrow_mut ( ) = Some ( RustfixDiagnosticServer :: new ( ) ?) ;
108+ opts. compile_opts . build_config . rustc_wrapper = Some ( wrapper) ;
124109
125110 ops:: compile ( ws, & opts. compile_opts ) ?;
126111 Ok ( ( ) )
@@ -207,7 +192,7 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
207192
208193 let args = FixArgs :: get ( ) ;
209194 trace ! ( "cargo-fix as rustc got file {:?}" , args. file) ;
210- let rustc = env :: var_os ( "RUSTC" ) . expect ( "failed to find RUSTC env var " ) ;
195+ let rustc = args . rustc . as_ref ( ) . expect ( "fix wrapper rustc was not set " ) ;
211196
212197 // Our goal is to fix only the crates that the end user is interested in.
213198 // That's very likely to only mean the crates in the workspace the user is
@@ -576,6 +561,7 @@ struct FixArgs {
576561 enabled_edition : Option < String > ,
577562 other : Vec < OsString > ,
578563 primary_package : bool ,
564+ rustc : Option < PathBuf > ,
579565}
580566
581567enum PrepareFor {
@@ -593,7 +579,8 @@ impl Default for PrepareFor {
593579impl FixArgs {
594580 fn get ( ) -> FixArgs {
595581 let mut ret = FixArgs :: default ( ) ;
596- for arg in env:: args_os ( ) . skip ( 1 ) {
582+ ret. rustc = env:: args_os ( ) . nth ( 1 ) . map ( PathBuf :: from) ;
583+ for arg in env:: args_os ( ) . skip ( 2 ) {
597584 let path = PathBuf :: from ( arg) ;
598585 if path. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "rs" ) && path. exists ( ) {
599586 ret. file = Some ( path) ;
0 commit comments