File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,11 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
281281 // - If the fix succeeded, show any remaining warnings.
282282 let mut cmd = Command :: new ( & rustc) ;
283283 args. apply ( & mut cmd) ;
284+ for arg in args. format_args {
285+ // Add any json/error format arguments that Cargo wants. This allows
286+ // things like colored output to work correctly.
287+ cmd. arg ( arg) ;
288+ }
284289 exit_with ( cmd. status ( ) . context ( "failed to spawn rustc" ) ?) ;
285290}
286291
@@ -587,6 +592,7 @@ struct FixArgs {
587592 other : Vec < OsString > ,
588593 rustc : Option < PathBuf > ,
589594 clippy_args : Vec < String > ,
595+ format_args : Vec < String > ,
590596}
591597
592598enum PrepareFor {
@@ -627,6 +633,7 @@ impl FixArgs {
627633 if s. starts_with ( "--error-format=" ) || s. starts_with ( "--json=" ) {
628634 // Cargo may add error-format in some cases, but `cargo
629635 // fix` wants to add its own.
636+ ret. format_args . push ( s. to_string ( ) ) ;
630637 continue ;
631638 }
632639 }
Original file line number Diff line number Diff line change @@ -1289,3 +1289,22 @@ fn fix_with_clippy() {
12891289 "
12901290 ) ;
12911291}
1292+
1293+ #[ cargo_test]
1294+ fn fix_color_message ( ) {
1295+ // Check that color appears in diagnostics.
1296+ let p = project ( )
1297+ . file ( "src/lib.rs" , "std::compile_error!{\" color test\" }" )
1298+ . build ( ) ;
1299+
1300+ p. cargo ( "fix --allow-no-vcs --color=always" )
1301+ . with_stderr_contains ( "[..]\x1b [[..]" )
1302+ . with_status ( 101 )
1303+ . run ( ) ;
1304+
1305+ p. cargo ( "fix --allow-no-vcs --color=never" )
1306+ . with_stderr_contains ( "error: color test" )
1307+ . with_stderr_does_not_contain ( "[..]\x1b [[..]" )
1308+ . with_status ( 101 )
1309+ . run ( ) ;
1310+ }
You can’t perform that action at this time.
0 commit comments