Skip to content

Commit 3973cf9

Browse files
committed
fix(ops): correct error message when using --broken-code
1 parent c63475b commit 3973cf9

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/cargo/ops/fix/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,6 @@ 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() {
798795
// No fixes were available. Display whatever errors happened.
799796
emit_output(&fixes.last_output)?;
@@ -814,6 +811,7 @@ pub fn fix_exec_rustc(gctx: &GlobalContext, lock_addr: &str) -> CargoResult<()>
814811
krate,
815812
&fixes.last_output.stderr,
816813
fixes.last_output.status,
814+
allow_broken_code,
817815
)?;
818816
// Display the diagnostics that appeared at the start, before the
819817
// fixes failed. This can help with diagnosing which suggestions
@@ -1171,6 +1169,7 @@ fn log_failed_fix(
11711169
krate: Option<String>,
11721170
stderr: &[u8],
11731171
status: ExitStatus,
1172+
allow_broken_code: bool,
11741173
) -> CargoResult<()> {
11751174
let stderr = str::from_utf8(stderr).context("failed to parse rustc stderr as utf-8")?;
11761175

@@ -1205,6 +1204,7 @@ fn log_failed_fix(
12051204
krate,
12061205
errors,
12071206
abnormal_exit,
1207+
allow_broken_code,
12081208
}
12091209
.post(gctx)?;
12101210

src/cargo/util/diagnostic_server.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub enum Message {
4040
krate: Option<String>,
4141
errors: Vec<String>,
4242
abnormal_exit: Option<String>,
43+
allow_broken_code: bool,
4344
},
4445
ReplaceFailed {
4546
file: String,
@@ -145,6 +146,7 @@ impl<'a> DiagnosticPrinter<'a> {
145146
krate,
146147
errors,
147148
abnormal_exit,
149+
allow_broken_code,
148150
} => {
149151
if let Some(ref krate) = *krate {
150152
self.gctx.shell().warn(&format!(
@@ -168,12 +170,21 @@ impl<'a> DiagnosticPrinter<'a> {
168170
}
169171
writeln!(self.gctx.shell().err())?;
170172
}
171-
let issue_link = get_bug_report_url(self.workspace_wrapper);
172-
write!(
173-
self.gctx.shell().err(),
174-
"{}",
175-
gen_please_report_this_bug_text(issue_link)
176-
)?;
173+
if *allow_broken_code {
174+
writeln!(
175+
self.gctx.shell().err(),
176+
"Fix failed, but broken code changes were saved as \
177+
requested with `--broken-code`.\n\
178+
The code needs to be manually reviewed and fixed.\n"
179+
)?;
180+
} else {
181+
let issue_link = get_bug_report_url(self.workspace_wrapper);
182+
write!(
183+
self.gctx.shell().err(),
184+
"{}",
185+
gen_please_report_this_bug_text(issue_link)
186+
)?;
187+
}
177188
if !errors.is_empty() {
178189
writeln!(
179190
self.gctx.shell().err(),

tests/testsuite/fix.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,12 @@ fn fix_to_broken_code() {
14321432
...
14331433
[WARNING] failed to automatically apply fixes suggested by rustc to crate `bar`
14341434
...
1435+
Fix failed, but broken code changes were saved as requested with `--broken-code`.
1436+
The code needs to be manually reviewed and fixed.
1437+
...
14351438
"#]])
1439+
.with_stderr_does_not_contain("[..]--broken-code[..]flag[..]")
1440+
.with_stderr_does_not_contain("[..]bug report[..]")
14361441
.run();
14371442

14381443
assert_e2e().eq(

0 commit comments

Comments
 (0)