Skip to content

Commit

Permalink
Make ICE backtrace actually match the panic handler
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 7, 2023
1 parent 8ad2379 commit b594807
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>() {
Some(s) => &s[..],
None => "Box<dyn Any>",
},
};
let thread = std::thread::current();
let name = thread.name().unwrap_or("<unnamed>");
let _ = write!(
&mut out,
"thread '{name}' panicked at {location}:\n\
{msg}\n\
stack backtrace:\n\
{:#}",
std::backtrace::Backtrace::force_capture()
);
}
}

Expand Down

0 comments on commit b594807

Please sign in to comment.