]> git.lizzy.rs Git - rust.git/blob - library/std/src/panic/tests.rs
Rollup merge of #104252 - faern:stabilize-const_socketaddr, r=JohnTitor
[rust.git] / library / std / src / panic / tests.rs
1 #![allow(dead_code)]
2
3 use crate::cell::RefCell;
4 use crate::panic::{AssertUnwindSafe, UnwindSafe};
5 use crate::rc::Rc;
6 use crate::sync::{Arc, Mutex, RwLock};
7
8 struct Foo {
9     a: i32,
10 }
11
12 fn assert<T: UnwindSafe + ?Sized>() {}
13
14 #[test]
15 fn panic_safety_traits() {
16     assert::<i32>();
17     assert::<&i32>();
18     assert::<*mut i32>();
19     assert::<*const i32>();
20     assert::<usize>();
21     assert::<str>();
22     assert::<&str>();
23     assert::<Foo>();
24     assert::<&Foo>();
25     assert::<Vec<i32>>();
26     assert::<String>();
27     assert::<RefCell<i32>>();
28     assert::<Box<i32>>();
29     assert::<Mutex<i32>>();
30     assert::<RwLock<i32>>();
31     assert::<&Mutex<i32>>();
32     assert::<&RwLock<i32>>();
33     assert::<Rc<i32>>();
34     assert::<Arc<i32>>();
35     assert::<Box<[u8]>>();
36
37     {
38         trait Trait: UnwindSafe {}
39         assert::<Box<dyn Trait>>();
40     }
41
42     fn bar<T>() {
43         assert::<Mutex<T>>();
44         assert::<RwLock<T>>();
45     }
46
47     fn baz<T: UnwindSafe>() {
48         assert::<Box<T>>();
49         assert::<Vec<T>>();
50         assert::<RefCell<T>>();
51         assert::<AssertUnwindSafe<T>>();
52         assert::<&AssertUnwindSafe<T>>();
53         assert::<Rc<AssertUnwindSafe<T>>>();
54         assert::<Arc<AssertUnwindSafe<T>>>();
55     }
56 }