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