@@ -51,7 +51,8 @@ use rustc_metadata::creader::MetadataLoader;
51
51
use rustc_metadata:: locator;
52
52
use rustc_parse:: { new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal} ;
53
53
use 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 ,
55
56
} ;
56
57
use rustc_session:: getopts:: { self , Matches } ;
57
58
use rustc_session:: lint:: { Lint , LintId } ;
@@ -301,6 +302,8 @@ fn run_compiler(
301
302
let Some ( matches) = handle_options( & default_early_dcx, & args) else { return Ok ( ( ) ) } ;
302
303
303
304
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_file = ice_path_with_config( Some ( & sopts. unstable_opts) ) ;
304
307
305
308
if let Some ( ref code) = matches. opt_str( "explain" ) {
306
309
handle_explain( & default_early_dcx, diagnostics_registry( ) , code, sopts. color) ;
@@ -315,7 +318,7 @@ fn run_compiler(
315
318
input: Input :: File ( PathBuf :: new( ) ) ,
316
319
output_file: ofile,
317
320
output_dir: odir,
318
- ice_file: ice_path ( ) . clone ( ) ,
321
+ ice_file,
319
322
file_loader,
320
323
locale_resources: DEFAULT_LOCALE_RESOURCES ,
321
324
lint_caps: Default :: default ( ) ,
@@ -357,7 +360,11 @@ fn run_compiler(
357
360
// printing some information without compiling, or exiting immediately
358
361
// after parsing, etc.
359
362
let early_exit = || {
360
- if let Some ( guar) = sess. dcx( ) . has_errors( ) { Err ( guar) } else { Ok ( ( ) ) }
363
+ if let Some ( guar) = sess. dcx( ) . has_errors( ) {
364
+ Err ( guar)
365
+ } else {
366
+ Ok ( ( ) )
367
+ }
361
368
} ;
362
369
363
370
// This implements `-Whelp`. It should be handled very early, like
@@ -567,7 +574,11 @@ fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, col
567
574
fn show_md_content_with_pager( content: & str , color: ColorConfig ) {
568
575
let mut fallback_to_println = false ;
569
576
let pager_name = env:: var_os( "PAGER" ) . unwrap_or_else( || {
570
- if cfg!( windows) { OsString :: from( "more.com" ) } else { OsString :: from( "less" ) }
577
+ if cfg!( windows) {
578
+ OsString :: from( "more.com" )
579
+ } else {
580
+ OsString :: from( "less" )
581
+ }
571
582
} ) ;
572
583
573
584
let mut cmd = Command :: new( & pager_name) ;
@@ -1306,16 +1317,26 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
1306
1317
1307
1318
static ICE_PATH : OnceLock <Option <PathBuf >> = OnceLock :: new( ) ;
1308
1319
1320
+ // This function should only be called from the ICE hook.
1321
+ //
1322
+ // The intended behavior is that `run_compiler` will invoke `ice_path_with_config` early in the
1323
+ // initialization process to properly initialize the ICE_PATH static based on parsed CLI flags.
1324
+ //
1325
+ // Subsequent calls to either function will then return the proper ICE path as configured by
1326
+ // the environment and cli flags
1309
1327
fn ice_path( ) -> & ' static Option <PathBuf > {
1328
+ ice_path_with_config( None )
1329
+ }
1330
+
1331
+ fn ice_path_with_config( config: Option <& UnstableOptions >) -> & ' static Option <PathBuf > {
1332
+ if ICE_PATH . get( ) . is_some( ) && config. is_some( ) && cfg!( debug_assertions) {
1333
+ warn!( "ICE_PATH has already been initialized -- files may be emitted at unintended paths" )
1334
+ }
1335
+
1310
1336
ICE_PATH . get_or_init( || {
1311
1337
if !rustc_feature:: UnstableFeatures :: from_environment( None ) . is_nightly_build( ) {
1312
1338
return None ;
1313
1339
}
1314
- if let Some ( s) = std:: env:: var_os( "RUST_BACKTRACE" )
1315
- && s == "0"
1316
- {
1317
- return None ;
1318
- }
1319
1340
let mut path = match std:: env:: var_os( "RUSTC_ICE" ) {
1320
1341
Some ( s) => {
1321
1342
if s == "0" {
@@ -1324,7 +1345,10 @@ fn ice_path() -> &'static Option<PathBuf> {
1324
1345
}
1325
1346
PathBuf :: from( s)
1326
1347
}
1327
- None => std:: env:: current_dir( ) . unwrap_or_default( ) ,
1348
+ None => config
1349
+ . and_then( |unstable_opts| unstable_opts. error_metrics. to_owned( ) )
1350
+ . or_else( || std:: env:: current_dir( ) . ok( ) )
1351
+ . unwrap_or_default( ) ,
1328
1352
} ;
1329
1353
let now: OffsetDateTime = SystemTime :: now( ) . into( ) ;
1330
1354
let file_now = now
0 commit comments