7 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -252,15 +252,23 @@ fn default_hook(info: &PanicInfo<'_>) {
252
252
let msg = match info. payload ( ) . downcast_ref :: < & ' static str > ( ) {
253
253
Some ( s) => * s,
254
254
None => match info. payload ( ) . downcast_ref :: < String > ( ) {
255
- Some ( s) => & s [ .. ] ,
255
+ Some ( s) => s . as_str ( ) ,
256
256
None => "Box<dyn Any>" ,
257
257
} ,
258
258
} ;
259
259
let thread = thread_info:: current_thread ( ) ;
260
- let name = thread. as_ref ( ) . and_then ( |t| t. name ( ) ) . unwrap_or ( "<unnamed>" ) ;
261
260
262
261
let write = |err : & mut dyn crate :: io:: Write | {
263
- let _ = writeln ! ( err, "thread '{name}' panicked at {location}:\n {msg}" ) ;
262
+ let _ = match thread. as_ref ( ) . map ( |t| t. name ( ) . ok_or ( t) ) {
263
+ Some ( Ok ( name) ) => {
264
+ writeln ! ( err, "thread '{name}' panicked at {location}:\n {msg}" )
265
+ }
266
+ Some ( Err ( t) ) => {
267
+ let id = t. id ( ) . as_u64 ( ) ;
268
+ writeln ! ( err, "thread '<unnamed>' (id {id}) panicked at {location}:\n {msg}" , )
269
+ }
270
+ None => writeln ! ( err, "thread '<unnamed>' panicked at {location}:\n {msg}" ) ,
271
+ } ;
264
272
265
273
static FIRST_PANIC : AtomicBool = AtomicBool :: new ( true ) ;
266
274
Original file line number Diff line number Diff line change 1
1
//@ignore-target-windows: No libc on Windows
2
2
3
3
//@compile-flags: -Zmiri-disable-abi-check
4
+ //@normalize-stderr-test: "thread '<unnamed>' \(id [0-9]+\)" -> "thread '<unnamed>'"
4
5
5
6
//! Unwinding past the top frame of a stack is Undefined Behavior.
6
7
Original file line number Diff line number Diff line change 1
1
//@compile-flags: -Zmiri-strict-provenance
2
+ //@normalize-stderr-test: "thread '<unnamed>' \(id [0-9]+\)" -> "thread '<unnamed>'"
2
3
3
4
use std:: thread;
4
5
Original file line number Diff line number Diff line change 1
1
// We are making scheduler assumptions here.
2
2
//@compile-flags: -Zmiri-preemption-rate=0
3
+ //@normalize-stderr-test: "thread '<unnamed>' \(id [0-9]+\)" -> "thread '<unnamed>'"
3
4
4
5
//! Cause a panic in one thread while another thread is unwinding. This checks
5
6
//! that separate threads have their own panicking state.
Original file line number Diff line number Diff line change
1
+ // Test panic error messages for unnamed threads
2
+
1
3
// run-fail
2
- // error-pattern:thread '<unnamed>' panicked
4
+ // regex- error-pattern:thread '<unnamed>' \(id \d+\) panicked
3
5
// error-pattern:test
4
6
// ignore-emscripten Needs threads
5
7
6
8
use std:: thread;
7
9
8
10
fn main ( ) {
9
- let r : Result < ( ) , _ > = thread:: spawn ( move || {
10
- panic ! ( "test" ) ;
11
- } )
12
- . join ( ) ;
13
- assert ! ( r . is_ok ( ) ) ;
11
+ let _ : ( ) = thread:: spawn ( move || {
12
+ panic ! ( "test" ) ;
13
+ } )
14
+ . join ( )
15
+ . unwrap ( ) ;
14
16
}
Original file line number Diff line number Diff line change 1
1
// aux-build:test-macros.rs
2
2
// compile-flags: -Z proc-macro-backtrace
3
3
// rustc-env:RUST_BACKTRACE=0
4
- // normalize-stderr-test "thread '.*' panicked " -> ""
4
+ // normalize-stderr-test "thread '.*' (\(id \d+\) )? panicked " -> ""
5
5
// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> ""
6
6
// needs-unwind proc macro panics to report errors
7
7
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ fn check_for_no_backtrace(test: std::process::Output) {
8
8
let err = String :: from_utf8_lossy ( & test. stderr ) ;
9
9
let mut it = err. lines ( ) ;
10
10
11
- assert_eq ! ( it. next( ) . map( |l| l. starts_with( "thread '<unnamed>' panicked " ) ) , Some ( true ) ) ;
11
+ assert_eq ! ( it. next( ) . map( |l| l. starts_with( "thread '<unnamed>' (id " ) ) , Some ( true ) ) ;
12
12
assert_eq ! ( it. next( ) . is_some( ) , true ) ;
13
13
assert_eq ! ( it. next( ) , Some ( "note: run with `RUST_BACKTRACE=1` \
14
14
environment variable to display a backtrace") ) ;
0 commit comments