Fix display of panic message in recursive panic. · model-checking/verify-rust-std@0c8a9e0 (original) (raw)
`@@ -641,6 +641,10 @@ pub fn begin_panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
`
641
641
`fn get(&mut self) -> &(dyn Any + Send) {
`
642
642
`&self.0
`
643
643
`}
`
``
644
+
``
645
`+
fn as_str(&mut self) -> Option<&str> {
`
``
646
`+
Some(self.0)
`
``
647
`+
}
`
644
648
`}
`
645
649
``
646
650
`impl fmt::Display for StaticStrPayload {
`
`@@ -763,15 +767,8 @@ fn rust_panic_with_hook(
`
763
767
`// Don't try to format the message in this case, perhaps that is causing the
`
764
768
`// recursive panics. However if the message is just a string, no user-defined
`
765
769
`// 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");
`
775
772
`}
`
776
773
` panic_count::MustAbort::AlwaysAbort => {
`
777
774
`// Unfortunately, this does not print a backtrace, because creating
`