about summary refs log tree commit diff
path: root/library/std/src/panicking.rs
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2024-05-16 12:59:09 +0200
committerMara Bos <m-ou.se@m-ou.se>2024-06-11 15:47:00 +0200
commitfb0990d1e1e67a512930665bf7df5fb91f55982c (patch)
treebfbee2cdba012f601103eefb1a55cf9b86ccb5ef /library/std/src/panicking.rs
parent877a26f6c9cbd9878ea08c94cd5a698a53556511 (diff)
downloadrust-fb0990d1e1e67a512930665bf7df5fb91f55982c.tar.gz
rust-fb0990d1e1e67a512930665bf7df5fb91f55982c.zip
Fix display of panic message in recursive panic.
Diffstat (limited to 'library/std/src/panicking.rs')
-rw-r--r--library/std/src/panicking.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs
index caab7ed4b81..e4d2ee7d986 100644
--- a/library/std/src/panicking.rs
+++ b/library/std/src/panicking.rs
@@ -641,6 +641,10 @@ pub fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
         fn get(&mut self) -> &(dyn Any + Send) {
             &self.0
         }
+
+        fn as_str(&mut self) -> Option<&str> {
+            Some(self.0)
+        }
     }
 
     impl fmt::Display for StaticStrPayload {
@@ -763,15 +767,8 @@ fn rust_panic_with_hook(
                 // Don't try to format the message in this case, perhaps that is causing the
                 // recursive panics. However if the message is just a string, no user-defined
                 // code is involved in printing it, so that is risk-free.
-                let msg_str = message.and_then(|m| m.as_str()).map(|m| [m]);
-                let message = msg_str.as_ref().map(|m| fmt::Arguments::new_const(m));
-                let panicinfo = PanicInfo::internal_constructor(
-                    message.as_ref(),
-                    location,
-                    can_unwind,
-                    force_no_backtrace,
-                );
-                rtprintpanic!("{panicinfo}\nthread panicked while processing panic. aborting.\n");
+                let message: &str = payload.as_str().unwrap_or_default();
+                rtprintpanic!("panicked at {location}:\n{message}\nthread panicked while processing panic. aborting.\n");
             }
             panic_count::MustAbort::AlwaysAbort => {
                 // Unfortunately, this does not print a backtrace, because creating