about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/panic/thread_panic.rs
blob: 9a3040b2c565ad2ef7a93dc2b6f43ca3b45b7803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! Panicking in other threads.

use std::thread;

fn panic() {
    let result = thread::spawn(|| panic!("Hello!")).join().unwrap_err();
    let msg = result.downcast_ref::<&'static str>().unwrap();
    assert_eq!(*msg, "Hello!");
}

fn panic_named() {
    thread::Builder::new()
        .name("childthread".to_string())
        .spawn(move || {
            panic!("Hello, world!");
        })
        .unwrap()
        .join()
        .unwrap_err();
}

fn main() {
    panic();
    panic_named();
}