@@ -139,6 +139,19 @@ pub mod target_features {
139
139
const BUG_REPORT_URL : & ' static str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
140
140
md#bug-reports";
141
141
142
+ const ICE_REPORT_COMPILER_FLAGS : & ' static [ & ' static str ] = & [
143
+ "Z" ,
144
+ "C" ,
145
+ "crate-type" ,
146
+ ] ;
147
+ const ICE_REPORT_COMPILER_FLAGS_EXCLUDE : & ' static [ & ' static str ] = & [
148
+ "metadata" ,
149
+ "extra-filename" ,
150
+ ] ;
151
+ const ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE : & ' static [ & ' static str ] = & [
152
+ "incremental" ,
153
+ ] ;
154
+
142
155
pub fn abort_on_err < T > ( result : Result < T , CompileIncomplete > , sess : & Session ) -> T {
143
156
match result {
144
157
Err ( CompileIncomplete :: Errored ( ErrorReported ) ) => {
@@ -1431,6 +1444,57 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
1431
1444
thread. unwrap ( ) . join ( )
1432
1445
}
1433
1446
1447
+ /// Get a list of extra command-line flags provided by the user, as strings.
1448
+ ///
1449
+ /// This function is used during ICEs to show more information useful for
1450
+ /// debugging, since some ICEs only happens with non-default compiler flags
1451
+ /// (and the users don't always report them).
1452
+ fn extra_compiler_flags ( ) -> Option < ( Vec < String > , bool ) > {
1453
+ let mut args = Vec :: new ( ) ;
1454
+ for arg in env:: args_os ( ) {
1455
+ args. push ( arg. to_string_lossy ( ) . to_string ( ) ) ;
1456
+ }
1457
+
1458
+ let matches = if let Some ( matches) = handle_options ( & args) {
1459
+ matches
1460
+ } else {
1461
+ return None ;
1462
+ } ;
1463
+
1464
+ let mut result = Vec :: new ( ) ;
1465
+ let mut excluded_cargo_defaults = false ;
1466
+ for flag in ICE_REPORT_COMPILER_FLAGS {
1467
+ let prefix = if flag. len ( ) == 1 { "-" } else { "--" } ;
1468
+
1469
+ for content in & matches. opt_strs ( flag) {
1470
+ // Split always returns the first element
1471
+ let name = if let Some ( first) = content. split ( '=' ) . next ( ) {
1472
+ first
1473
+ } else {
1474
+ & content
1475
+ } ;
1476
+
1477
+ let content = if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE . contains ( & name) {
1478
+ name
1479
+ } else {
1480
+ content
1481
+ } ;
1482
+
1483
+ if !ICE_REPORT_COMPILER_FLAGS_EXCLUDE . contains ( & name) {
1484
+ result. push ( format ! ( "{}{} {}" , prefix, flag, content) ) ;
1485
+ } else {
1486
+ excluded_cargo_defaults = true ;
1487
+ }
1488
+ }
1489
+ }
1490
+
1491
+ if result. len ( ) > 0 {
1492
+ Some ( ( result, excluded_cargo_defaults) )
1493
+ } else {
1494
+ None
1495
+ }
1496
+ }
1497
+
1434
1498
/// Run a procedure which will detect panics in the compiler and print nicer
1435
1499
/// error messages rather than just failing the test.
1436
1500
///
@@ -1462,11 +1526,22 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
1462
1526
errors:: Level :: Bug ) ;
1463
1527
}
1464
1528
1465
- let xs = [ "the compiler unexpectedly panicked. this is a bug." . to_string ( ) ,
1466
- format ! ( "we would appreciate a bug report: {}" , BUG_REPORT_URL ) ,
1467
- format ! ( "rustc {} running on {}" ,
1468
- option_env!( "CFG_VERSION" ) . unwrap_or( "unknown_version" ) ,
1469
- config:: host_triple( ) ) ] ;
1529
+ let mut xs = vec ! [
1530
+ "the compiler unexpectedly panicked. this is a bug." . to_string( ) ,
1531
+ format!( "we would appreciate a bug report: {}" , BUG_REPORT_URL ) ,
1532
+ format!( "rustc {} running on {}" ,
1533
+ option_env!( "CFG_VERSION" ) . unwrap_or( "unknown_version" ) ,
1534
+ config:: host_triple( ) ) ,
1535
+ ] ;
1536
+
1537
+ if let Some ( ( flags, excluded_cargo_defaults) ) = extra_compiler_flags ( ) {
1538
+ xs. push ( format ! ( "compiler flags: {}" , flags. join( " " ) ) ) ;
1539
+
1540
+ if excluded_cargo_defaults {
1541
+ xs. push ( "some of the compiler flags provided by cargo are hidden" . to_string ( ) ) ;
1542
+ }
1543
+ }
1544
+
1470
1545
for note in & xs {
1471
1546
handler. emit ( & MultiSpan :: new ( ) ,
1472
1547
& note,
0 commit comments