]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/panic-handler-flail-wildly.rs
Account for --remap-path-prefix in save-analysis
[rust.git] / src / test / run-pass / panic-handler-flail-wildly.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 #![feature(panic_handler, std_panic)]
11
12 // ignore-emscripten no threads support
13
14 use std::panic;
15 use std::thread;
16
17 fn a() {
18     panic::set_hook(Box::new(|_| println!("hello yes this is a")));
19     panic::take_hook();
20     panic::set_hook(Box::new(|_| println!("hello yes this is a part 2")));
21     panic::take_hook();
22 }
23
24 fn b() {
25     panic::take_hook();
26     panic::take_hook();
27     panic::take_hook();
28     panic::take_hook();
29     panic::take_hook();
30     panic!();
31 }
32
33 fn c() {
34     panic::set_hook(Box::new(|_| ()));
35     panic::set_hook(Box::new(|_| ()));
36     panic::set_hook(Box::new(|_| ()));
37     panic::set_hook(Box::new(|_| ()));
38     panic::set_hook(Box::new(|_| ()));
39     panic::set_hook(Box::new(|_| ()));
40     panic!();
41 }
42
43 fn main() {
44     for _ in 0..10 {
45         let mut handles = vec![];
46         for _ in 0..10 {
47             handles.push(thread::spawn(a));
48         }
49         for _ in 0..10 {
50             handles.push(thread::spawn(b));
51         }
52         for _ in 0..10 {
53             handles.push(thread::spawn(c));
54         }
55         for handle in handles {
56             let _ = handle.join();
57         }
58     }
59 }