From 2a02a49059d76ef13bedb398db4e06cfb68b4494 Mon Sep 17 00:00:00 2001 From: malezjaa Date: Sat, 19 Sep 2026 19:20:48 +0200 Subject: [PATCH] make ice hook respect color config --- compiler/rustc_driver_impl/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 1ba7ce953b5d4..90a242f03e818 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -203,6 +203,7 @@ pub fn compiler_entrypoint(at_args: &[String], callbacks: &mut (dyn Callbacks + let sopts = config::build_session_options(&mut default_early_dcx, &matches, warn_unspecified_edition); let ice_file = ice_path_with_config(Some(&sopts.unstable_opts)).clone(); + let _ = ICE_COLOR.set(sopts.color); if let Some(ref code) = matches.opt_str("explain") { handle_explain(&default_early_dcx, code, sopts.color); @@ -1392,6 +1393,7 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> T) -> ExitCode { } } +static ICE_COLOR: OnceLock = OnceLock::new(); static ICE_PATH: OnceLock> = OnceLock::new(); // This function should only be called from the ICE hook. @@ -1538,9 +1540,10 @@ fn report_ice( extra_info: fn(DiagCtxtHandle<'_>), using_internal_features: &AtomicBool, ) { + let color = ICE_COLOR.get().copied().unwrap_or(ColorConfig::Auto); let emitter = Box::new(rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitter::new( - stderr_destination(rustc_errors::ColorConfig::Auto), + stderr_destination(color), )); let dcx = DiagCtxt::new(emitter); let dcx = dcx.handle();