Skip to content

Commit 3b6c4d0

Browse files
committed
Correct the bug report for cargo clippy --fix
Signed-off-by: hi-rustin <[email protected]>
1 parent 41f7888 commit 3b6c4d0

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

src/cargo/core/compiler/job_queue/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ impl<'cfg> DrainState<'cfg> {
630630
self.bump_warning_count(id, emitted, fixable);
631631
}
632632
Message::FixDiagnostic(msg) => {
633-
self.print.print(&msg)?;
633+
self.print.print(&msg, &cx.bcx.rustc().workspace_wrapper)?;
634634
}
635635
Message::Finish(id, artifact, result) => {
636636
let unit = match artifact {

src/cargo/util/diagnostic_server.rs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::collections::HashSet;
55
use std::io::{BufReader, Read, Write};
66
use std::net::{Shutdown, SocketAddr, TcpListener, TcpStream};
7+
use std::path::PathBuf;
78
use std::sync::atomic::{AtomicBool, Ordering};
89
use std::sync::Arc;
910
use std::thread::{self, JoinHandle};
@@ -18,16 +19,6 @@ use crate::util::errors::CargoResult;
1819
use crate::util::Config;
1920

2021
const DIAGNOSTICS_SERVER_VAR: &str = "__CARGO_FIX_DIAGNOSTICS_SERVER";
21-
const PLEASE_REPORT_THIS_BUG: &str =
22-
"This likely indicates a bug in either rustc or cargo itself,\n\
23-
and we would appreciate a bug report! You're likely to see \n\
24-
a number of compiler warnings after this message which cargo\n\
25-
attempted to fix but failed. If you could open an issue at\n\
26-
https://github.com/rust-lang/rust/issues\n\
27-
quoting the full output of this command we'd be very appreciative!\n\
28-
Note that you may be able to make some more progress in the near-term\n\
29-
fixing code with the `--broken-code` flag\n\n\
30-
";
3122

3223
#[derive(Deserialize, Serialize, Hash, Eq, PartialEq, Clone)]
3324
pub enum Message {
@@ -96,7 +87,11 @@ impl<'a> DiagnosticPrinter<'a> {
9687
}
9788
}
9889

99-
pub fn print(&mut self, msg: &Message) -> CargoResult<()> {
90+
pub fn print(
91+
&mut self,
92+
msg: &Message,
93+
rustc_workspace_wrapper: &Option<PathBuf>,
94+
) -> CargoResult<()> {
10095
match msg {
10196
Message::Migrating {
10297
file,
@@ -128,7 +123,12 @@ impl<'a> DiagnosticPrinter<'a> {
128123
"The full error message was:\n\n> {}\n\n",
129124
message,
130125
)?;
131-
write!(self.config.shell().err(), "{}", PLEASE_REPORT_THIS_BUG)?;
126+
let issue_link = get_bug_report_url(rustc_workspace_wrapper);
127+
write!(
128+
self.config.shell().err(),
129+
"{}",
130+
gen_please_report_this_bug_text(issue_link)
131+
)?;
132132
Ok(())
133133
}
134134
Message::FixFailed {
@@ -159,7 +159,12 @@ impl<'a> DiagnosticPrinter<'a> {
159159
}
160160
writeln!(self.config.shell().err())?;
161161
}
162-
write!(self.config.shell().err(), "{}", PLEASE_REPORT_THIS_BUG)?;
162+
let issue_link = get_bug_report_url(rustc_workspace_wrapper);
163+
write!(
164+
self.config.shell().err(),
165+
"{}",
166+
gen_please_report_this_bug_text(issue_link)
167+
)?;
163168
if !errors.is_empty() {
164169
writeln!(
165170
self.config.shell().err(),
@@ -218,6 +223,31 @@ https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-proje
218223
}
219224
}
220225

226+
fn gen_please_report_this_bug_text(url: &str) -> String {
227+
format!(
228+
"This likely indicates a bug in either rustc or cargo itself,\n\
229+
and we would appreciate a bug report! You're likely to see \n\
230+
a number of compiler warnings after this message which cargo\n\
231+
attempted to fix but failed. If you could open an issue at\n\
232+
{}\n\
233+
quoting the full output of this command we'd be very appreciative!\n\
234+
Note that you may be able to make some more progress in the near-term\n\
235+
fixing code with the `--broken-code` flag\n\n\
236+
",
237+
url
238+
)
239+
}
240+
241+
fn get_bug_report_url(rustc_workspace_wrapper: &Option<PathBuf>) -> &str {
242+
let clippy = std::ffi::OsStr::new("clippy-driver");
243+
let issue_link = match rustc_workspace_wrapper.as_ref().and_then(|x| x.file_stem()) {
244+
Some(wrapper) if wrapper == clippy => "https://github.com/rust-lang/rust-clippy/issues",
245+
_ => "https://github.com/rust-lang/rust/issues",
246+
};
247+
248+
issue_link
249+
}
250+
221251
#[derive(Debug)]
222252
pub struct RustfixDiagnosticServer {
223253
listener: TcpListener,

0 commit comments

Comments
 (0)