]> git.lizzy.rs Git - rust.git/blob - src/test/ui/panics/panic-handler-flail-wildly.rs
Rollup merge of #105843 - compiler-errors:sugg-const, r=lcnr
[rust.git] / src / test / ui / panics / panic-handler-flail-wildly.rs
1 // run-pass
2 // needs-unwind
3
4 #![allow(stable_features)]
5 #![allow(unused_must_use)]
6
7 // ignore-emscripten no threads support
8
9 #![feature(std_panic)]
10
11 use std::panic;
12 use std::thread;
13
14 fn a() {
15     panic::set_hook(Box::new(|_| println!("hello yes this is a")));
16     panic::take_hook();
17     panic::set_hook(Box::new(|_| println!("hello yes this is a part 2")));
18     panic::take_hook();
19 }
20
21 fn b() {
22     panic::take_hook();
23     panic::take_hook();
24     panic::take_hook();
25     panic::take_hook();
26     panic::take_hook();
27     panic!();
28 }
29
30 fn c() {
31     panic::set_hook(Box::new(|_| ()));
32     panic::set_hook(Box::new(|_| ()));
33     panic::set_hook(Box::new(|_| ()));
34     panic::set_hook(Box::new(|_| ()));
35     panic::set_hook(Box::new(|_| ()));
36     panic::set_hook(Box::new(|_| ()));
37     panic!();
38 }
39
40 fn main() {
41     for _ in 0..10 {
42         let mut handles = vec![];
43         for _ in 0..10 {
44             handles.push(thread::spawn(a));
45         }
46         for _ in 0..10 {
47             handles.push(thread::spawn(b));
48         }
49         for _ in 0..10 {
50             handles.push(thread::spawn(c));
51         }
52         for handle in handles {
53             let _ = handle.join();
54         }
55     }
56 }