Skip to content

Commit b594807

Browse files
Make ICE backtrace actually match the panic handler
1 parent 8ad2379 commit b594807

File tree

1 file changed

+19
-2
lines changed
  • compiler/rustc_driver_impl/src

1 file changed

+19
-2
lines changed

compiler/rustc_driver_impl/src/lib.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1350,8 +1350,25 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
13501350
&& let Ok(mut out) =
13511351
File::options().create(true).append(true).open(&ice_path)
13521352
{
1353-
let _ =
1354-
write!(&mut out, "{info}{:#}", std::backtrace::Backtrace::force_capture());
1353+
// The current implementation always returns `Some`.
1354+
let location = info.location().unwrap();
1355+
let msg = match info.payload().downcast_ref::<&'static str>() {
1356+
Some(s) => *s,
1357+
None => match info.payload().downcast_ref::<String>() {
1358+
Some(s) => &s[..],
1359+
None => "Box<dyn Any>",
1360+
},
1361+
};
1362+
let thread = std::thread::current();
1363+
let name = thread.name().unwrap_or("<unnamed>");
1364+
let _ = write!(
1365+
&mut out,
1366+
"thread '{name}' panicked at {location}:\n\
1367+
{msg}\n\
1368+
stack backtrace:\n\
1369+
{:#}",
1370+
std::backtrace::Backtrace::force_capture()
1371+
);
13551372
}
13561373
}
13571374

0 commit comments

Comments
 (0)