Skip to content

Commit bb982d7

Browse files
committed
Auto merge of #112849 - m-ou-se:panic-message-format, r=thomcc
Change default panic handler message format. This changes the default panic hook's message format from: ``` thread '{thread}' panicked at '{message}', {location} ``` to ``` thread '{thread}' panicked at {location}: {message} ``` This puts the message on its own line without surrounding quotes, making it easiser to read. For example: Before: ``` thread 'main' panicked at 'env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`', src/main.rs:4:6 ``` After: ``` thread 'main' panicked at src/main.rs:4:6: env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh` ``` --- See this PR by `@nyurik,` which does that for only multi-line messages (specifically because of `assert_eq`): rust-lang/rust#111071 This is the change that does that for *all* panic messages.
2 parents ff1e280 + 24bc56b commit bb982d7

33 files changed

+98
-49
lines changed

tests/fail/concurrency/unwind_top_of_stack.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread '<unnamed>' panicked at 'explicit panic', $DIR/unwind_top_of_stack.rs:LL:CC
1+
thread '<unnamed>' panicked at $DIR/unwind_top_of_stack.rs:LL:CC:
2+
explicit panic
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: Undefined Behavior: unwinding past the topmost frame of the stack
45
--> $DIR/unwind_top_of_stack.rs:LL:CC

tests/fail/function_calls/exported_symbol_bad_unwind1.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'explicit panic', $DIR/exported_symbol_bad_unwind1.rs:LL:CC
1+
thread 'main' panicked at $DIR/exported_symbol_bad_unwind1.rs:LL:CC:
2+
explicit panic
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: Undefined Behavior: unwinding past a stack frame that does not allow unwinding
45
--> $DIR/exported_symbol_bad_unwind1.rs:LL:CC

tests/fail/function_calls/exported_symbol_bad_unwind2.both.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'explicit panic', $DIR/exported_symbol_bad_unwind2.rs:LL:CC
1+
thread 'main' panicked at $DIR/exported_symbol_bad_unwind2.rs:LL:CC:
2+
explicit panic
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: abnormal termination: panic in a function that cannot unwind
45
--> $DIR/exported_symbol_bad_unwind2.rs:LL:CC

tests/fail/function_calls/exported_symbol_bad_unwind2.definition.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'explicit panic', $DIR/exported_symbol_bad_unwind2.rs:LL:CC
1+
thread 'main' panicked at $DIR/exported_symbol_bad_unwind2.rs:LL:CC:
2+
explicit panic
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: abnormal termination: panic in a function that cannot unwind
45
--> $DIR/exported_symbol_bad_unwind2.rs:LL:CC

tests/fail/function_calls/exported_symbol_bad_unwind2.extern_block.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'explicit panic', $DIR/exported_symbol_bad_unwind2.rs:LL:CC
1+
thread 'main' panicked at $DIR/exported_symbol_bad_unwind2.rs:LL:CC:
2+
explicit panic
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: Undefined Behavior: unwinding past a stack frame that does not allow unwinding
45
--> $DIR/exported_symbol_bad_unwind2.rs:LL:CC

tests/fail/panic/bad_unwind.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'explicit panic', $DIR/bad_unwind.rs:LL:CC
1+
thread 'main' panicked at $DIR/bad_unwind.rs:LL:CC:
2+
explicit panic
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: Undefined Behavior: unwinding past a stack frame that does not allow unwinding
45
--> $DIR/bad_unwind.rs:LL:CC

tests/fail/panic/double_panic.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
thread 'main' panicked at 'first', $DIR/double_panic.rs:LL:CC
1+
thread 'main' panicked at $DIR/double_panic.rs:LL:CC:
2+
first
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3-
thread 'main' panicked at 'second', $DIR/double_panic.rs:LL:CC
4+
thread 'main' panicked at $DIR/double_panic.rs:LL:CC:
5+
second
46
stack backtrace:
57
error: abnormal termination: panic in a function that cannot unwind
68
--> $DIR/double_panic.rs:LL:CC

tests/fail/panic/no_std.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
panicked at 'blarg I am dead', $DIR/no_std.rs:LL:CC
1+
panicked at $DIR/no_std.rs:LL:CC:
2+
blarg I am dead
23
error: abnormal termination: the program aborted execution
34
--> $DIR/no_std.rs:LL:CC
45
|

tests/fail/panic/panic_abort1.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'panicking from libstd', $DIR/panic_abort1.rs:LL:CC
1+
thread 'main' panicked at $DIR/panic_abort1.rs:LL:CC:
2+
panicking from libstd
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: abnormal termination: the program aborted execution
45
--> RUSTLIB/panic_abort/src/lib.rs:LL:CC

tests/fail/panic/panic_abort2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at '42-panicking from libstd', $DIR/panic_abort2.rs:LL:CC
1+
thread 'main' panicked at $DIR/panic_abort2.rs:LL:CC:
2+
42-panicking from libstd
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: abnormal termination: the program aborted execution
45
--> RUSTLIB/panic_abort/src/lib.rs:LL:CC

tests/fail/panic/panic_abort3.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'panicking from libcore', $DIR/panic_abort3.rs:LL:CC
1+
thread 'main' panicked at $DIR/panic_abort3.rs:LL:CC:
2+
panicking from libcore
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: abnormal termination: the program aborted execution
45
--> RUSTLIB/panic_abort/src/lib.rs:LL:CC

tests/fail/panic/panic_abort4.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at '42-panicking from libcore', $DIR/panic_abort4.rs:LL:CC
1+
thread 'main' panicked at $DIR/panic_abort4.rs:LL:CC:
2+
42-panicking from libcore
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: abnormal termination: the program aborted execution
45
--> RUSTLIB/panic_abort/src/lib.rs:LL:CC

tests/fail/panic/thread_local_const_drop_panic.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread $NAME panicked at 'ow', $DIR/thread_local_const_drop_panic.rs:LL:CC
1+
thread $NAME panicked at $DIR/thread_local_const_drop_panic.rs:LL:CC:
2+
ow
23
fatal runtime error: thread local panicked on drop
34
error: abnormal termination: the program aborted execution
45

tests/fail/panic/thread_local_drop_panic.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread $NAME panicked at 'ow', $DIR/thread_local_drop_panic.rs:LL:CC
1+
thread $NAME panicked at $DIR/thread_local_drop_panic.rs:LL:CC:
2+
ow
23
fatal runtime error: thread local panicked on drop
34
error: abnormal termination: the program aborted execution
45

tests/fail/terminate-terminator.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
warning: You have explicitly enabled MIR optimizations, overriding Miri's default which is to completely disable them. Any optimizations may hide UB that Miri would otherwise detect, and it is not necessarily possible to predict what kind of UB will be missed. If you are enabling optimizations to make Miri run faster, we advise using cfg(miri) to shrink your workload instead. The performance benefit of enabling MIR optimizations is usually marginal at best.
22

3-
thread 'main' panicked at 'explicit panic', $DIR/terminate-terminator.rs:LL:CC
3+
thread 'main' panicked at $DIR/terminate-terminator.rs:LL:CC:
4+
explicit panic
45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
56
error: abnormal termination: panic in a function that cannot unwind
67
--> $DIR/terminate-terminator.rs:LL:CC

tests/fail/unwind-action-terminate.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'explicit panic', $DIR/unwind-action-terminate.rs:LL:CC
1+
thread 'main' panicked at $DIR/unwind-action-terminate.rs:LL:CC:
2+
explicit panic
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
error: abnormal termination: panic in a function that cannot unwind
45
--> $DIR/unwind-action-terminate.rs:LL:CC

tests/panic/div-by-zero-2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'attempt to divide by zero', $DIR/div-by-zero-2.rs:LL:CC
1+
thread 'main' panicked at $DIR/div-by-zero-2.rs:LL:CC:
2+
attempt to divide by zero
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
thread 'main' panicked at 'explicit panic', $DIR/exported_symbol_good_unwind.rs:LL:CC
1+
thread 'main' panicked at $DIR/exported_symbol_good_unwind.rs:LL:CC:
2+
explicit panic
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3-
thread 'main' panicked at 'explicit panic', $DIR/exported_symbol_good_unwind.rs:LL:CC
4-
thread 'main' panicked at 'explicit panic', $DIR/exported_symbol_good_unwind.rs:LL:CC
4+
thread 'main' panicked at $DIR/exported_symbol_good_unwind.rs:LL:CC:
5+
explicit panic
6+
thread 'main' panicked at $DIR/exported_symbol_good_unwind.rs:LL:CC:
7+
explicit panic

tests/panic/oob_subslice.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'range end index 5 out of range for slice of length 4', $DIR/oob_subslice.rs:LL:CC
1+
thread 'main' panicked at $DIR/oob_subslice.rs:LL:CC:
2+
range end index 5 out of range for slice of length 4
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'attempt to shift left with overflow', $DIR/overflowing-lsh-neg.rs:LL:CC
1+
thread 'main' panicked at $DIR/overflowing-lsh-neg.rs:LL:CC:
2+
attempt to shift left with overflow
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/overflowing-rsh-1.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-1.rs:LL:CC
1+
thread 'main' panicked at $DIR/overflowing-rsh-1.rs:LL:CC:
2+
attempt to shift right with overflow
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/overflowing-rsh-2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-2.rs:LL:CC
1+
thread 'main' panicked at $DIR/overflowing-rsh-2.rs:LL:CC:
2+
attempt to shift right with overflow
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/panic1.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
thread 'main' panicked at 'panicking from libstd', $DIR/panic1.rs:LL:CC
1+
thread 'main' panicked at $DIR/panic1.rs:LL:CC:
2+
panicking from libstd
23
stack backtrace:
34
0: std::panicking::begin_panic_handler
45
at RUSTLIB/std/src/panicking.rs:LL:CC

tests/panic/panic2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at '42-panicking from libstd', $DIR/panic2.rs:LL:CC
1+
thread 'main' panicked at $DIR/panic2.rs:LL:CC:
2+
42-panicking from libstd
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/panic3.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'panicking from libcore', $DIR/panic3.rs:LL:CC
1+
thread 'main' panicked at $DIR/panic3.rs:LL:CC:
2+
panicking from libcore
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/panic4.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at '42-panicking from libcore', $DIR/panic4.rs:LL:CC
1+
thread 'main' panicked at $DIR/panic4.rs:LL:CC:
2+
42-panicking from libcore
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/transmute_fat2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', $DIR/transmute_fat2.rs:LL:CC
1+
thread 'main' panicked at $DIR/transmute_fat2.rs:LL:CC:
2+
index out of bounds: the len is 0 but the index is 0
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'unsupported Miri functionality: can't call foreign function `foo` on $OS', $DIR/unsupported_foreign_function.rs:LL:CC
1+
thread 'main' panicked at $DIR/unsupported_foreign_function.rs:LL:CC:
2+
unsupported Miri functionality: can't call foreign function `foo` on $OS
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'unsupported Miri functionality: can't execute syscall with ID 0', $DIR/unsupported_syscall.rs:LL:CC
1+
thread 'main' panicked at $DIR/unsupported_syscall.rs:LL:CC:
2+
unsupported Miri functionality: can't execute syscall with ID 0
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/pass/concurrency/simple.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
thread '<unnamed>' panicked at 'Hello!', $DIR/simple.rs:LL:CC
1+
thread '<unnamed>' panicked at $DIR/simple.rs:LL:CC:
2+
Hello!
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3-
thread 'childthread' panicked at 'Hello, world!', $DIR/simple.rs:LL:CC
4+
thread 'childthread' panicked at $DIR/simple.rs:LL:CC:
5+
Hello, world!

tests/pass/panic/catch_panic.stderr

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
1-
thread 'main' panicked at 'Hello from panic: std', $DIR/catch_panic.rs:LL:CC
1+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
2+
Hello from panic: std
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
Caught panic message (&str): Hello from panic: std
4-
thread 'main' panicked at 'Hello from panic: 1', $DIR/catch_panic.rs:LL:CC
5+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
6+
Hello from panic: 1
57
Caught panic message (String): Hello from panic: 1
6-
thread 'main' panicked at 'Hello from panic: 2', $DIR/catch_panic.rs:LL:CC
8+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
9+
Hello from panic: 2
710
Caught panic message (String): Hello from panic: 2
8-
thread 'main' panicked at 'Box<dyn Any>', $DIR/catch_panic.rs:LL:CC
11+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
12+
Box<dyn Any>
913
Failed to get caught panic message.
10-
thread 'main' panicked at 'Hello from panic: core', $DIR/catch_panic.rs:LL:CC
14+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
15+
Hello from panic: core
1116
Caught panic message (&str): Hello from panic: core
12-
thread 'main' panicked at 'Hello from panic: 5', $DIR/catch_panic.rs:LL:CC
17+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
18+
Hello from panic: 5
1319
Caught panic message (String): Hello from panic: 5
14-
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4', $DIR/catch_panic.rs:LL:CC
20+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
21+
index out of bounds: the len is 3 but the index is 4
1522
Caught panic message (String): index out of bounds: the len is 3 but the index is 4
16-
thread 'main' panicked at 'attempt to divide by zero', $DIR/catch_panic.rs:LL:CC
23+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
24+
attempt to divide by zero
1725
Caught panic message (&str): attempt to divide by zero
18-
thread 'main' panicked at 'align_offset: align is not a power-of-two', RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC
26+
thread 'main' panicked at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC:
27+
align_offset: align is not a power-of-two
1928
Caught panic message (&str): align_offset: align is not a power-of-two
20-
thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:LL:CC
29+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
30+
assertion failed: false
2131
Caught panic message (&str): assertion failed: false
22-
thread 'main' panicked at 'assertion failed: false', $DIR/catch_panic.rs:LL:CC
32+
thread 'main' panicked at $DIR/catch_panic.rs:LL:CC:
33+
assertion failed: false
2334
Caught panic message (&str): assertion failed: false
2435
Success!
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Thread 1 starting, will block on mutex
22
Thread 1 reported it has started
3-
thread '<unnamed>' panicked at 'panic in thread 2', $DIR/concurrent-panic.rs:LL:CC
3+
thread '<unnamed>' panicked at $DIR/concurrent-panic.rs:LL:CC:
4+
panic in thread 2
45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
56
Thread 2 blocking on thread 1
67
Thread 2 reported it has started
78
Unlocking mutex
8-
thread '<unnamed>' panicked at 'panic in thread 1', $DIR/concurrent-panic.rs:LL:CC
9+
thread '<unnamed>' panicked at $DIR/concurrent-panic.rs:LL:CC:
10+
panic in thread 1
911
Thread 1 has exited
1012
Thread 2 has exited
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
thread 'main' panicked at 'once', $DIR/nested_panic_caught.rs:LL:CC
1+
thread 'main' panicked at $DIR/nested_panic_caught.rs:LL:CC:
2+
once
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3-
thread 'main' panicked at 'twice', $DIR/nested_panic_caught.rs:LL:CC
4+
thread 'main' panicked at $DIR/nested_panic_caught.rs:LL:CC:
5+
twice
46
stack backtrace:

0 commit comments

Comments
 (0)