From b59480784dce3e02c3ce804d3fd383e2ebede465 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 7 Sep 2023 05:33:36 +0000 Subject: [PATCH] Make ICE backtrace actually match the panic handler --- compiler/rustc_driver_impl/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 35f4ff7d964e2..9cfb599aff4cb 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1350,8 +1350,25 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler)) && let Ok(mut out) = File::options().create(true).append(true).open(&ice_path) { - let _ = - write!(&mut out, "{info}{:#}", std::backtrace::Backtrace::force_capture()); + // The current implementation always returns `Some`. + let location = info.location().unwrap(); + let msg = match info.payload().downcast_ref::<&'static str>() { + Some(s) => *s, + None => match info.payload().downcast_ref::() { + Some(s) => &s[..], + None => "Box", + }, + }; + let thread = std::thread::current(); + let name = thread.name().unwrap_or(""); + let _ = write!( + &mut out, + "thread '{name}' panicked at {location}:\n\ + {msg}\n\ + stack backtrace:\n\ + {:#}", + std::backtrace::Backtrace::force_capture() + ); } }