Skip to content

Commit cadecc2

Browse files
compiler-errorscuviper
authored andcommitted
Make ICE backtrace actually match the panic handler
(cherry picked from commit b594807)
1 parent 5d064f2 commit cadecc2

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
@@ -1390,8 +1390,25 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
13901390
&& let Ok(mut out) =
13911391
File::options().create(true).append(true).open(&ice_path)
13921392
{
1393-
let _ =
1394-
write!(&mut out, "{info}{:#}", std::backtrace::Backtrace::force_capture());
1393+
// The current implementation always returns `Some`.
1394+
let location = info.location().unwrap();
1395+
let msg = match info.payload().downcast_ref::<&'static str>() {
1396+
Some(s) => *s,
1397+
None => match info.payload().downcast_ref::<String>() {
1398+
Some(s) => &s[..],
1399+
None => "Box<dyn Any>",
1400+
},
1401+
};
1402+
let thread = std::thread::current();
1403+
let name = thread.name().unwrap_or("<unnamed>");
1404+
let _ = write!(
1405+
&mut out,
1406+
"thread '{name}' panicked at {location}:\n\
1407+
{msg}\n\
1408+
stack backtrace:\n\
1409+
{:#}",
1410+
std::backtrace::Backtrace::force_capture()
1411+
);
13951412
}
13961413
}
13971414

0 commit comments

Comments
 (0)