Skip to content

Commit f2a7a5d

Browse files
committed
fix(ops): add warning when no fixes suggested with --broken-code
1 parent 2292462 commit f2a7a5d

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/cargo/ops/fix/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,16 @@ pub fn fix_exec_rustc(gctx: &GlobalContext, lock_addr: &str) -> CargoResult<()>
791791

792792
// If there were any fixes, let the user know that there was a failure
793793
// attempting to apply them, and to ask for a bug report.
794-
//
795-
// FIXME: The error message here is not correct with --broken-code.
796-
// https://github.com/rust-lang/cargo/issues/10955
797794
if fixes.files.is_empty() {
795+
if allow_broken_code {
796+
gctx.shell()
797+
.warn("no fixes were suggested because the code is already broken")?;
798+
gctx.shell().note(
799+
"cargo fix requires code that compiles successfully to apply automatic fixes",
800+
)?;
801+
gctx.shell()
802+
.note("the broken code was saved due to --broken-code")?;
803+
}
798804
// No fixes were available. Display whatever errors happened.
799805
emit_output(&fixes.last_output)?;
800806
exit_with(fixes.last_output.status);

tests/testsuite/fix.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,9 @@ fn fix_in_rust_src() {
23802380
.with_status(101)
23812381
.with_stderr_data(str![[r#"
23822382
[CHECKING] foo v0.0.0 ([ROOT]/foo)
2383+
[WARNING] no fixes were suggested because the code is already broken
2384+
[NOTE] cargo fix requires code that compiles successfully to apply automatic fixes
2385+
[NOTE] the broken code was saved due to --broken-code
23832386
error[E0308]: mismatched types
23842387
--> lib.rs:5:9
23852388
|

tests/testsuite/fix_n_times.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ fn broken_code_no_suggestions() {
550550
},
551551
str![[r#"
552552
[CHECKING] foo v0.0.1 ([ROOT]/foo)
553+
[WARNING] no fixes were suggested because the code is already broken
554+
[NOTE] cargo fix requires code that compiles successfully to apply automatic fixes
555+
[NOTE] the broken code was saved due to --broken-code
553556
rustc fix shim error count=1
554557
[ERROR] could not compile `foo` (lib) due to 1 previous error
555558

0 commit comments

Comments
 (0)