@@ -1287,17 +1287,21 @@ pub fn ice_path() -> &'static Option<PathBuf> {
1287
1287
if !rustc_feature:: UnstableFeatures :: from_environment( None ) . is_nightly_build( ) {
1288
1288
return None ;
1289
1289
}
1290
- if let Ok ( "0" ) = std:: env:: var ( "RUST_BACKTRACE" ) . as_deref ( ) {
1290
+ if let Some ( s ) = std:: env:: var_os ( "RUST_BACKTRACE" ) && s == "0" {
1291
1291
return None ;
1292
1292
}
1293
- let mut path = match std:: env:: var( "RUSTC_ICE" ) . as_deref( ) {
1294
- // Explicitly opting out of writing ICEs to disk.
1295
- Ok ( "0" ) => return None ,
1296
- Ok ( s) => PathBuf :: from( s) ,
1297
- Err ( _) => std:: env:: current_dir( ) . unwrap_or_default( ) ,
1293
+ let mut path = match std:: env:: var_os( "RUSTC_ICE" ) {
1294
+ Some ( s) => {
1295
+ if s == "0" {
1296
+ // Explicitly opting out of writing ICEs to disk.
1297
+ return None ;
1298
+ }
1299
+ PathBuf :: from( s)
1300
+ }
1301
+ None => std:: env:: current_dir( ) . unwrap_or_default( ) ,
1298
1302
} ;
1299
1303
let now: OffsetDateTime = SystemTime :: now( ) . into( ) ;
1300
- let file_now = now. format( & Rfc3339 ) . unwrap_or ( String :: new ( ) ) ;
1304
+ let file_now = now. format( & Rfc3339 ) . unwrap_or_default ( ) ;
1301
1305
let pid = std:: process:: id( ) ;
1302
1306
path. push( format!( "rustc-ice-{file_now}-{pid}.txt" ) ) ;
1303
1307
Some ( path)
@@ -1322,7 +1326,7 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
1322
1326
// by the user. Compiler developers and other rustc users can
1323
1327
// opt in to less-verbose backtraces by manually setting "RUST_BACKTRACE"
1324
1328
// (e.g. `RUST_BACKTRACE=1`)
1325
- if std:: env:: var ( "RUST_BACKTRACE" ) . is_err ( ) {
1329
+ if std:: env:: var_os ( "RUST_BACKTRACE" ) . is_none ( ) {
1326
1330
std:: env:: set_var( "RUST_BACKTRACE" , "full" ) ;
1327
1331
}
1328
1332
@@ -1411,12 +1415,11 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info:
1411
1415
1412
1416
static FIRST_PANIC : AtomicBool = AtomicBool :: new( true ) ;
1413
1417
1414
- let file = if let Some ( path) = ice_path( ) . as_ref ( ) {
1418
+ let file = if let Some ( path) = ice_path( ) {
1415
1419
// Create the ICE dump target file.
1416
1420
match crate :: fs:: File :: options( ) . create( true ) . append( true ) . open( & path) {
1417
1421
Ok ( mut file) => {
1418
- handler
1419
- . emit_note( session_diagnostics:: IcePath { path: path. display( ) . to_string( ) } ) ;
1422
+ handler. emit_note( session_diagnostics:: IcePath { path: path. clone( ) } ) ;
1420
1423
if FIRST_PANIC . swap( false , Ordering :: SeqCst ) {
1421
1424
let _ = write!( file, "\n \n rustc version: {version}\n platform: {triple}" ) ;
1422
1425
}
@@ -1425,10 +1428,10 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info:
1425
1428
Err ( err) => {
1426
1429
// The path ICE couldn't be written to disk, provide feedback to the user as to why.
1427
1430
handler. emit_warning( session_diagnostics:: IcePathError {
1428
- path: path. display ( ) . to_string ( ) ,
1431
+ path: path. clone ( ) ,
1429
1432
error: err. to_string( ) ,
1430
- env_var: std:: env:: var ( "RUSTC_ICE" )
1431
- . ok ( )
1433
+ env_var: std:: env:: var_os ( "RUSTC_ICE" )
1434
+ . map ( PathBuf :: from )
1432
1435
. map( |env_var| session_diagnostics:: IcePathErrorEnv { env_var } ) ,
1433
1436
} ) ;
1434
1437
handler. emit_note( session_diagnostics:: IceVersion { version, triple } ) ;
0 commit comments