@@ -51,7 +51,8 @@ use rustc_metadata::creader::MetadataLoader;
5151use rustc_metadata:: locator;
5252use rustc_parse:: { new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal} ;
5353use rustc_session:: config:: {
54- nightly_options, ErrorOutputType , Input , OutFileName , OutputType , CG_OPTIONS , Z_OPTIONS ,
54+ nightly_options, ErrorOutputType , Input , OutFileName , OutputType , UnstableOptions , CG_OPTIONS ,
55+ Z_OPTIONS ,
5556} ;
5657use rustc_session:: getopts:: { self , Matches } ;
5758use rustc_session:: lint:: { Lint , LintId } ;
@@ -301,6 +302,8 @@ fn run_compiler(
301302 let Some ( matches) = handle_options( & default_early_dcx, & args) else { return Ok ( ( ) ) } ;
302303
303304 let sopts = config:: build_session_options( & mut default_early_dcx, & matches) ;
305+ // fully initialize ice path static once unstable options are available as context
306+ let _ = ice_path_with_config( Some ( & sopts. unstable_opts) ) ;
304307
305308 if let Some ( ref code) = matches. opt_str( "explain" ) {
306309 handle_explain( & default_early_dcx, diagnostics_registry( ) , code, sopts. color) ;
@@ -1307,15 +1310,14 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
13071310static ICE_PATH : OnceLock <Option <PathBuf >> = OnceLock :: new( ) ;
13081311
13091312fn ice_path( ) -> & ' static Option <PathBuf > {
1313+ ice_path_with_config( None )
1314+ }
1315+
1316+ fn ice_path_with_config( config: Option <& UnstableOptions >) -> & ' static Option <PathBuf > {
13101317 ICE_PATH . get_or_init( || {
13111318 if !rustc_feature:: UnstableFeatures :: from_environment( None ) . is_nightly_build( ) {
13121319 return None ;
13131320 }
1314- if let Some ( s) = std:: env:: var_os( "RUST_BACKTRACE" )
1315- && s == "0"
1316- {
1317- return None ;
1318- }
13191321 let mut path = match std:: env:: var_os( "RUSTC_ICE" ) {
13201322 Some ( s) => {
13211323 if s == "0" {
@@ -1324,7 +1326,10 @@ fn ice_path() -> &'static Option<PathBuf> {
13241326 }
13251327 PathBuf :: from( s)
13261328 }
1327- None => std:: env:: current_dir( ) . unwrap_or_default( ) ,
1329+ None => config
1330+ . and_then( |unstable_opts| unstable_opts. error_metrics. to_owned( ) )
1331+ . or_else( || std:: env:: current_dir( ) . ok( ) )
1332+ . unwrap_or_default( ) ,
13281333 } ;
13291334 let now: OffsetDateTime = SystemTime :: now( ) . into( ) ;
13301335 let file_now = now
0 commit comments