@@ -1287,17 +1287,21 @@ pub fn ice_path() -> &'static Option<PathBuf> {
12871287 if !rustc_feature:: UnstableFeatures :: from_environment( None ) . is_nightly_build( ) {
12881288 return None ;
12891289 }
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" {
12911291 return None ;
12921292 }
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( ) ,
12981302 } ;
12991303 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 ( ) ;
13011305 let pid = std:: process:: id( ) ;
13021306 path. push( format!( "rustc-ice-{file_now}-{pid}.txt" ) ) ;
13031307 Some ( path)
@@ -1322,7 +1326,7 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
13221326 // by the user. Compiler developers and other rustc users can
13231327 // opt in to less-verbose backtraces by manually setting "RUST_BACKTRACE"
13241328 // (e.g. `RUST_BACKTRACE=1`)
1325- if std:: env:: var ( "RUST_BACKTRACE" ) . is_err ( ) {
1329+ if std:: env:: var_os ( "RUST_BACKTRACE" ) . is_none ( ) {
13261330 std:: env:: set_var( "RUST_BACKTRACE" , "full" ) ;
13271331 }
13281332
@@ -1411,12 +1415,11 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info:
14111415
14121416 static FIRST_PANIC : AtomicBool = AtomicBool :: new( true ) ;
14131417
1414- let file = if let Some ( path) = ice_path( ) . as_ref ( ) {
1418+ let file = if let Some ( path) = ice_path( ) {
14151419 // Create the ICE dump target file.
14161420 match crate :: fs:: File :: options( ) . create( true ) . append( true ) . open( & path) {
14171421 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( ) } ) ;
14201423 if FIRST_PANIC . swap( false , Ordering :: SeqCst ) {
14211424 let _ = write!( file, "\n \n rustc version: {version}\n platform: {triple}" ) ;
14221425 }
@@ -1425,10 +1428,10 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info:
14251428 Err ( err) => {
14261429 // The path ICE couldn't be written to disk, provide feedback to the user as to why.
14271430 handler. emit_warning( session_diagnostics:: IcePathError {
1428- path: path. display ( ) . to_string ( ) ,
1431+ path: path. clone ( ) ,
14291432 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 )
14321435 . map( |env_var| session_diagnostics:: IcePathErrorEnv { env_var } ) ,
14331436 } ) ;
14341437 handler. emit_note( session_diagnostics:: IceVersion { version, triple } ) ;
0 commit comments