Skip to content

Commit 0d1cab9

Browse files
authored
Rollup merge of rust-lang#122930 - RalfJung:panic-in-panic-fmt, r=Amanieu
add panic location to 'panicked while processing panic' Fixes rust-lang#97181 r? `@Amanieu`
2 parents 953c42c + f3dcd4a commit 0d1cab9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

core/src/panic/panic_info.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,12 @@ impl fmt::Display for PanicInfo<'_> {
161161
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
162162
formatter.write_str("panicked at ")?;
163163
self.location.fmt(formatter)?;
164+
formatter.write_str(":")?;
164165
if let Some(message) = self.message {
165-
formatter.write_str(":\n")?;
166+
formatter.write_str("\n")?;
166167
formatter.write_fmt(*message)?;
167168
} else if let Some(payload) = self.payload.downcast_ref::<&'static str>() {
168-
formatter.write_str(":\n")?;
169+
formatter.write_str("\n")?;
169170
formatter.write_str(payload)?;
170171
}
171172
// NOTE: we cannot use downcast_ref::<String>() here

std/src/panicking.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,13 @@ fn rust_panic_with_hook(
746746
panic_count::MustAbort::PanicInHook => {
747747
// Don't try to print the message in this case
748748
// - perhaps that is causing the recursive panics.
749-
rtprintpanic!("thread panicked while processing panic. aborting.\n");
749+
let panicinfo = PanicInfo::internal_constructor(
750+
None, // no message
751+
location, // but we want to show the location!
752+
can_unwind,
753+
force_no_backtrace,
754+
);
755+
rtprintpanic!("{panicinfo}\nthread panicked while processing panic. aborting.\n");
750756
}
751757
panic_count::MustAbort::AlwaysAbort => {
752758
// Unfortunately, this does not print a backtrace, because creating

0 commit comments

Comments
 (0)