Skip to content

Commit d28ca0b

Browse files
committed
Auto merge of #9831 - ehuss:fix-debug, r=Eh2406
Add some debug logging for `cargo fix` This adds some debug logging to the `cargo fix` command to give better insight into what it is actually doing. I've needed to try to debug some things recently where this would have been useful, since cargo runs rustc many times with different arguments. I think this will be useful if other people report problems, we can ask them to run with `CARGO_LOG=cargo::ops::fix=trace` to gather more information.
2 parents 835d557 + 9fe4a4e commit d28ca0b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cargo/ops/fix.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
364364
let mut cmd = rustc.build_command();
365365
args.apply(&mut cmd, config);
366366
cmd.arg("--error-format=json");
367+
debug!("calling rustc for final verification: {:?}", cmd);
367368
let output = cmd.output().context("failed to spawn rustc")?;
368369

369370
if output.status.success() {
@@ -389,6 +390,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
389390
if !output.status.success() {
390391
if env::var_os(BROKEN_CODE_ENV).is_none() {
391392
for (path, file) in fixes.files.iter() {
393+
debug!("reverting {:?} due to errors", path);
392394
paths::write(path, &file.original_code)?;
393395
}
394396
}
@@ -407,6 +409,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
407409
// things like colored output to work correctly.
408410
cmd.arg(arg);
409411
}
412+
debug!("calling rustc to display remaining diagnostics: {:?}", cmd);
410413
exit_with(cmd.status().context("failed to spawn rustc")?);
411414
}
412415

@@ -545,6 +548,10 @@ fn rustfix_and_fix(
545548
let mut cmd = rustc.build_command();
546549
cmd.arg("--error-format=json");
547550
args.apply(&mut cmd, config);
551+
debug!(
552+
"calling rustc to collect suggestions and validate previous fixes: {:?}",
553+
cmd
554+
);
548555
let output = cmd.output().with_context(|| {
549556
format!(
550557
"failed to execute `{}`",
@@ -609,6 +616,7 @@ fn rustfix_and_fix(
609616
continue;
610617
}
611618

619+
trace!("adding suggestion for {:?}: {:?}", file_name, suggestion);
612620
file_map
613621
.entry(file_name)
614622
.or_insert_with(Vec::new)

0 commit comments

Comments
 (0)