Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c8a9e0

Browse files
committed
Fix display of panic message in recursive panic.
1 parent2f85702 commit0c8a9e0

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

‎core/src/panic.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,9 @@ pub unsafe trait PanicPayload: crate::fmt::Display {
157157

158158
/// Just borrow the contents.
159159
fnget(&mutself) ->&(dynAny +Send);
160+
161+
/// Try to borrow the contents as `&str`, if possible without doing any allocations.
162+
fnas_str(&mutself) ->Option<&str>{
163+
None
164+
}
160165
}

‎std/src/panicking.rs‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ pub fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
641641
fnget(&mutself) ->&(dynAny +Send){
642642
&self.0
643643
}
644+
645+
fnas_str(&mutself) ->Option<&str>{
646+
Some(self.0)
647+
}
644648
}
645649

646650
impl fmt::DisplayforStaticStrPayload{
@@ -763,15 +767,8 @@ fn rust_panic_with_hook(
763767
// Don't try to format the message in this case, perhaps that is causing the
764768
// recursive panics. However if the message is just a string, no user-defined
765769
// code is involved in printing it, so that is risk-free.
766-
let msg_str = message.and_then(|m| m.as_str()).map(|m|[m]);
767-
let message = msg_str.as_ref().map(|m| fmt::Arguments::new_const(m));
768-
let panicinfo =PanicInfo::internal_constructor(
769-
message.as_ref(),
770-
location,
771-
can_unwind,
772-
force_no_backtrace,
773-
);
774-
rtprintpanic!("{panicinfo}\nthread panicked while processing panic. aborting.\n");
770+
let message:&str = payload.as_str().unwrap_or_default();
771+
rtprintpanic!("panicked at {location}:\n{message}\nthread panicked while processing panic. aborting.\n");
775772
}
776773
panic_count::MustAbort::AlwaysAbort =>{
777774
// Unfortunately, this does not print a backtrace, because creating

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp