@@ -42,7 +42,7 @@ use std::collections::{BTreeSet, HashMap, HashSet};
42
42
use std:: env;
43
43
use std:: ffi:: OsString ;
44
44
use std:: path:: { Path , PathBuf } ;
45
- use std:: process:: { self , Command , ExitStatus } ;
45
+ use std:: process:: { self , ExitStatus } ;
46
46
use std:: str;
47
47
48
48
use anyhow:: { bail, Context , Error } ;
@@ -353,9 +353,15 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
353
353
. ok ( ) ;
354
354
let mut rustc = ProcessBuilder :: new ( & args. rustc ) . wrapped ( workspace_rustc. as_ref ( ) ) ;
355
355
rustc. env_remove ( FIX_ENV ) ;
356
+ args. apply ( & mut rustc) ;
356
357
357
358
trace ! ( "start rustfixing {:?}" , args. file) ;
358
- let fixes = rustfix_crate ( & lock_addr, & rustc, & args. file , & args, config) ?;
359
+ let json_error_rustc = {
360
+ let mut cmd = rustc. clone ( ) ;
361
+ cmd. arg ( "--error-format=json" ) ;
362
+ cmd
363
+ } ;
364
+ let fixes = rustfix_crate ( & lock_addr, & json_error_rustc, & args. file , & args, config) ?;
359
365
360
366
// Ok now we have our final goal of testing out the changes that we applied.
361
367
// If these changes went awry and actually started to cause the crate to
@@ -366,11 +372,8 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
366
372
// new rustc, and otherwise we capture the output to hide it in the scenario
367
373
// that we have to back it all out.
368
374
if !fixes. files . is_empty ( ) {
369
- let mut cmd = rustc. build_command ( ) ;
370
- args. apply ( & mut cmd) ;
371
- cmd. arg ( "--error-format=json" ) ;
372
- debug ! ( "calling rustc for final verification: {:?}" , cmd) ;
373
- let output = cmd. output ( ) . context ( "failed to spawn rustc" ) ?;
375
+ debug ! ( "calling rustc for final verification: {json_error_rustc}" ) ;
376
+ let output = json_error_rustc. output ( ) ?;
374
377
375
378
if output. status . success ( ) {
376
379
for ( path, file) in fixes. files . iter ( ) {
@@ -407,15 +410,13 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
407
410
// - If the fix failed, show the original warnings and suggestions.
408
411
// - If `--broken-code`, show the error messages.
409
412
// - If the fix succeeded, show any remaining warnings.
410
- let mut cmd = rustc. build_command ( ) ;
411
- args. apply ( & mut cmd) ;
412
413
for arg in args. format_args {
413
414
// Add any json/error format arguments that Cargo wants. This allows
414
415
// things like colored output to work correctly.
415
- cmd . arg ( arg) ;
416
+ rustc . arg ( arg) ;
416
417
}
417
- debug ! ( "calling rustc to display remaining diagnostics: {:?}" , cmd ) ;
418
- exit_with ( cmd . status ( ) . context ( "failed to spawn rustc" ) ?) ;
418
+ debug ! ( "calling rustc to display remaining diagnostics: {rustc}" ) ;
419
+ exit_with ( rustc . status ( ) ?) ;
419
420
}
420
421
421
422
#[ derive( Default ) ]
@@ -502,7 +503,7 @@ fn rustfix_crate(
502
503
// We'll generate new errors below.
503
504
file. errors_applying_fixes . clear ( ) ;
504
505
}
505
- rustfix_and_fix ( & mut fixes, rustc, filename, args , config) ?;
506
+ rustfix_and_fix ( & mut fixes, rustc, filename, config) ?;
506
507
let mut progress_yet_to_be_made = false ;
507
508
for ( path, file) in fixes. files . iter_mut ( ) {
508
509
if file. errors_applying_fixes . is_empty ( ) {
@@ -543,26 +544,14 @@ fn rustfix_and_fix(
543
544
fixes : & mut FixedCrate ,
544
545
rustc : & ProcessBuilder ,
545
546
filename : & Path ,
546
- args : & FixArgs ,
547
547
config : & Config ,
548
548
) -> Result < ( ) , Error > {
549
549
// If not empty, filter by these lints.
550
550
// TODO: implement a way to specify this.
551
551
let only = HashSet :: new ( ) ;
552
552
553
- let mut cmd = rustc. build_command ( ) ;
554
- cmd. arg ( "--error-format=json" ) ;
555
- args. apply ( & mut cmd) ;
556
- debug ! (
557
- "calling rustc to collect suggestions and validate previous fixes: {:?}" ,
558
- cmd
559
- ) ;
560
- let output = cmd. output ( ) . with_context ( || {
561
- format ! (
562
- "failed to execute `{}`" ,
563
- rustc. get_program( ) . to_string_lossy( )
564
- )
565
- } ) ?;
553
+ debug ! ( "calling rustc to collect suggestions and validate previous fixes: {rustc}" ) ;
554
+ let output = rustc. output ( ) ?;
566
555
567
556
// If rustc didn't succeed for whatever reasons then we're very likely to be
568
557
// looking at otherwise broken code. Let's not make things accidentally
@@ -834,7 +823,7 @@ impl FixArgs {
834
823
} )
835
824
}
836
825
837
- fn apply ( & self , cmd : & mut Command ) {
826
+ fn apply ( & self , cmd : & mut ProcessBuilder ) {
838
827
cmd. arg ( & self . file ) ;
839
828
cmd. args ( & self . other ) ;
840
829
if self . prepare_for_edition . is_some ( ) {
0 commit comments