]> git.lizzy.rs Git - rust.git/blob - src/test/ui/panics/panic-recover-propagate.rs
Auto merge of #103600 - compiler-errors:early-binder-nits, r=spastorino
[rust.git] / src / test / ui / panics / panic-recover-propagate.rs
1 // run-pass
2 // needs-unwind
3 // ignore-emscripten no threads support
4
5 use std::sync::atomic::{AtomicUsize, Ordering};
6 use std::panic;
7 use std::thread;
8
9 static A: AtomicUsize = AtomicUsize::new(0);
10
11 fn main() {
12     panic::set_hook(Box::new(|_| {
13         A.fetch_add(1, Ordering::SeqCst);
14     }));
15
16     let result = thread::spawn(|| {
17         let result = panic::catch_unwind(|| {
18             panic!("hi there");
19         });
20
21         panic::resume_unwind(result.unwrap_err());
22     }).join();
23
24     let msg = *result.unwrap_err().downcast::<&'static str>().unwrap();
25     assert_eq!("hi there", msg);
26     assert_eq!(1, A.load(Ordering::SeqCst));
27 }