@@ -66,7 +66,7 @@ pub const EXIT_FAILURE: i32 = 1;
6666const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rust/issues/new\
6767 ?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md";
6868
69- const ICE_REPORT_COMPILER_FLAGS : & [ & str ] = & [ "Z" , "C" , "crate-type" ] ;
69+ const ICE_REPORT_COMPILER_FLAGS : & [ & str ] = & [ "- Z" , "- C" , "-- crate-type" ] ;
7070
7171const ICE_REPORT_COMPILER_FLAGS_EXCLUDE : & [ & str ] = & [ "metadata" , "extra-filename" ] ;
7272
@@ -1100,31 +1100,31 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<as
11001100/// debugging, since some ICEs only happens with non-default compiler flags
11011101/// (and the users don't always report them).
11021102fn extra_compiler_flags ( ) -> Option < ( Vec < String > , bool ) > {
1103- let args = env:: args_os ( ) . map ( |arg| arg. to_string_lossy ( ) . to_string ( ) ) . collect :: < Vec < _ > > ( ) ;
1103+ let mut args = env:: args_os ( ) . map ( |arg| arg. to_string_lossy ( ) . to_string ( ) ) . peekable ( ) ;
11041104
1105- // Avoid printing help because of empty args. This can suggest the compiler
1106- // itself is not the program root (consider RLS).
1107- if args. len ( ) < 2 {
1108- return None ;
1109- }
1110-
1111- let matches = handle_options ( & args) ?;
11121105 let mut result = Vec :: new ( ) ;
11131106 let mut excluded_cargo_defaults = false ;
1114- for flag in ICE_REPORT_COMPILER_FLAGS {
1115- let prefix = if flag. len ( ) == 1 { "-" } else { "--" } ;
1116-
1117- for content in & matches. opt_strs ( flag) {
1118- // Split always returns the first element
1119- let name = if let Some ( first) = content. split ( '=' ) . next ( ) { first } else { & content } ;
1120-
1121- let content =
1122- if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE . contains ( & name) { name } else { content } ;
1123-
1124- if !ICE_REPORT_COMPILER_FLAGS_EXCLUDE . contains ( & name) {
1125- result. push ( format ! ( "{}{} {}" , prefix, flag, content) ) ;
1107+ while let Some ( arg) = args. next ( ) {
1108+ if let Some ( a) = ICE_REPORT_COMPILER_FLAGS . iter ( ) . find ( |a| arg. starts_with ( * a) ) {
1109+ let content = if arg. len ( ) == a. len ( ) {
1110+ match args. next ( ) {
1111+ Some ( arg) => arg. to_string ( ) ,
1112+ None => continue ,
1113+ }
1114+ } else if arg. get ( a. len ( ) ..a. len ( ) + 1 ) == Some ( "=" ) {
1115+ arg[ a. len ( ) + 1 ..] . to_string ( )
11261116 } else {
1117+ arg[ a. len ( ) ..] . to_string ( )
1118+ } ;
1119+ if ICE_REPORT_COMPILER_FLAGS_EXCLUDE . iter ( ) . any ( |exc| content. starts_with ( exc) ) {
11271120 excluded_cargo_defaults = true ;
1121+ } else {
1122+ result. push ( a. to_string ( ) ) ;
1123+ match ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE . iter ( ) . find ( |s| content. starts_with ( * s) )
1124+ {
1125+ Some ( s) => result. push ( s. to_string ( ) ) ,
1126+ None => result. push ( content) ,
1127+ }
11281128 }
11291129 }
11301130 }
@@ -1240,6 +1240,15 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12401240///
12411241/// A custom rustc driver can skip calling this to set up a custom ICE hook.
12421242pub fn install_ice_hook ( ) {
1243+ // If the user has not explicitly overriden "RUST_BACKTRACE", then produce
1244+ // full backtraces. When a compiler ICE happens, we want to gather
1245+ // as much information as possible to present in the issue opened
1246+ // by the user. Compiler developers and other rustc users can
1247+ // opt in to less-verbose backtraces by manually setting "RUST_BACKTRACE"
1248+ // (e.g. `RUST_BACKTRACE=1`)
1249+ if std:: env:: var ( "RUST_BACKTRACE" ) . is_err ( ) {
1250+ std:: env:: set_var ( "RUST_BACKTRACE" , "full" ) ;
1251+ }
12431252 SyncLazy :: force ( & DEFAULT_HOOK ) ;
12441253}
12451254
0 commit comments