Skip to content

Commit 9f64276

Browse files
committed
Move panic safety traits tests
1 parent 09e1d33 commit 9f64276

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

core/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ mod nonzero;
7878
mod num;
7979
mod ops;
8080
mod option;
81+
mod panic_safe;
8182
mod pattern;
8283
mod ptr;
8384
mod result;

core/tests/panic_safe.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#![allow(dead_code)]
2+
3+
use std::cell::RefCell;
4+
use std::panic::{AssertUnwindSafe, UnwindSafe};
5+
use std::rc::Rc;
6+
use std::sync::{Arc, Mutex, RwLock};
7+
8+
struct Foo {
9+
a: i32,
10+
}
11+
12+
fn assert<T: UnwindSafe + ?Sized>() {}
13+
14+
#[test]
15+
fn test_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+
}

0 commit comments

Comments
 (0)