Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
// - If the fix succeeded, show any remaining warnings.
let mut cmd = Command::new(&rustc);
args.apply(&mut cmd);
for arg in args.format_args {
// Add any json/error format arguments that Cargo wants. This allows
// things like colored output to work correctly.
cmd.arg(arg);
}
exit_with(cmd.status().context("failed to spawn rustc")?);
}

Expand Down Expand Up @@ -587,6 +592,7 @@ struct FixArgs {
other: Vec<OsString>,
rustc: Option<PathBuf>,
clippy_args: Vec<String>,
format_args: Vec<String>,
}

enum PrepareFor {
Expand Down Expand Up @@ -627,6 +633,7 @@ impl FixArgs {
if s.starts_with("--error-format=") || s.starts_with("--json=") {
// Cargo may add error-format in some cases, but `cargo
// fix` wants to add its own.
ret.format_args.push(s.to_string());
continue;
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,3 +1289,22 @@ fn fix_with_clippy() {
"
);
}

#[cargo_test]
fn fix_color_message() {
// Check that color appears in diagnostics.
let p = project()
.file("src/lib.rs", "std::compile_error!{\"color test\"}")
.build();

p.cargo("fix --allow-no-vcs --color=always")
.with_stderr_contains("[..]\x1b[[..]")
.with_status(101)
.run();

p.cargo("fix --allow-no-vcs --color=never")
.with_stderr_contains("error: color test")
.with_stderr_does_not_contain("[..]\x1b[[..]")
.with_status(101)
.run();
}