@@ -66,7 +66,7 @@ pub const EXIT_FAILURE: i32 = 1;
66
66
const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rust/issues/new\
67
67
?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md";
68
68
69
- const ICE_REPORT_COMPILER_FLAGS : & [ & str ] = & [ "Z" , "C" , "crate-type" ] ;
69
+ const ICE_REPORT_COMPILER_FLAGS : & [ & str ] = & [ "- Z" , "- C" , "-- crate-type" ] ;
70
70
71
71
const ICE_REPORT_COMPILER_FLAGS_EXCLUDE : & [ & str ] = & [ "metadata" , "extra-filename" ] ;
72
72
@@ -1100,31 +1100,31 @@ fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<as
1100
1100
/// debugging, since some ICEs only happens with non-default compiler flags
1101
1101
/// (and the users don't always report them).
1102
1102
fn 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 ( ) ;
1104
1104
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) ?;
1112
1105
let mut result = Vec :: new ( ) ;
1113
1106
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 ( )
1126
1116
} else {
1117
+ arg[ a. len ( ) ..] . to_string ( )
1118
+ } ;
1119
+ if ICE_REPORT_COMPILER_FLAGS_EXCLUDE . iter ( ) . any ( |exc| content. starts_with ( exc) ) {
1127
1120
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
+ }
1128
1128
}
1129
1129
}
1130
1130
}
@@ -1240,6 +1240,15 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
1240
1240
///
1241
1241
/// A custom rustc driver can skip calling this to set up a custom ICE hook.
1242
1242
pub 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
+ }
1243
1252
SyncLazy :: force ( & DEFAULT_HOOK ) ;
1244
1253
}
1245
1254
0 commit comments