This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +37
-3
lines changed Expand file tree Collapse file tree 4 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -161,11 +161,12 @@ impl fmt::Display for PanicInfo<'_> {
161
161
fn fmt ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
162
162
formatter. write_str ( "panicked at " ) ?;
163
163
self . location . fmt ( formatter) ?;
164
+ formatter. write_str ( ":" ) ?;
164
165
if let Some ( message) = self . message {
165
- formatter. write_str ( ": \n " ) ?;
166
+ formatter. write_str ( "\n " ) ?;
166
167
formatter. write_fmt ( * message) ?;
167
168
} else if let Some ( payload) = self . payload . downcast_ref :: < & ' static str > ( ) {
168
- formatter. write_str ( ": \n " ) ?;
169
+ formatter. write_str ( "\n " ) ?;
169
170
formatter. write_str ( payload) ?;
170
171
}
171
172
// NOTE: we cannot use downcast_ref::<String>() here
Original file line number Diff line number Diff line change @@ -746,7 +746,13 @@ fn rust_panic_with_hook(
746
746
panic_count:: MustAbort :: PanicInHook => {
747
747
// Don't try to print the message in this case
748
748
// - 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}\n thread panicked while processing panic. aborting.\n " ) ;
750
756
}
751
757
panic_count:: MustAbort :: AlwaysAbort => {
752
758
// Unfortunately, this does not print a backtrace, because creating
Original file line number Diff line number Diff line change
1
+ // Checks what happens when formatting the panic message panics.
2
+
3
+ //@ run-fail
4
+ //@ exec-env:RUST_BACKTRACE=0
5
+ //@ check-run-results
6
+ //@ error-pattern: panicked while processing panic
7
+ //@ normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> ""
8
+ //@ normalize-stderr-test: "\n +at [^\n]+" -> ""
9
+ //@ normalize-stderr-test: "(core/src/panicking\.rs):[0-9]+:[0-9]+" -> "$1:$$LINE:$$COL"
10
+ //@ ignore-emscripten "RuntimeError" junk in output
11
+
12
+ use std:: fmt:: { Display , self } ;
13
+
14
+ struct MyStruct ;
15
+
16
+ impl Display for MyStruct {
17
+ fn fmt ( & self , _: & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
18
+ todo ! ( )
19
+ }
20
+ }
21
+
22
+ fn main ( ) {
23
+ let instance = MyStruct ;
24
+ panic ! ( "this is wrong: {}" , instance) ;
25
+ }
Original file line number Diff line number Diff line change
1
+ panicked at $DIR/panic-in-message-fmt.rs:18:9:
2
+ thread panicked while processing panic. aborting.
You can’t perform that action at this time.
0 commit comments