44use std:: collections:: HashSet ;
55use std:: io:: { BufReader , Read , Write } ;
66use std:: net:: { Shutdown , SocketAddr , TcpListener , TcpStream } ;
7+ use std:: path:: PathBuf ;
78use std:: sync:: atomic:: { AtomicBool , Ordering } ;
89use std:: sync:: Arc ;
910use std:: thread:: { self , JoinHandle } ;
@@ -18,16 +19,6 @@ use crate::util::errors::CargoResult;
1819use crate :: util:: Config ;
1920
2021const 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 ) ]
3324pub 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 ) ]
222252pub struct RustfixDiagnosticServer {
223253 listener : TcpListener ,
0 commit comments