about summary refs log tree commit diff
path: root/library/core/tests
diff options
context:
space:
mode:
authorAlexis Bourget <alexis.bourget@gmail.com>2020-09-10 15:15:30 +0200
committerAlexis Bourget <alexis.bourget@gmail.com>2020-09-21 21:50:26 +0200
commitac39debeba2b63a39a3833e2d7451f0b1f95b5f2 (patch)
tree4e02eb9012072d41444e0eafc3ebcdff5f3b69d7 /library/core/tests
parented52c7bb7516f12f74704e20457d5046378a49fc (diff)
downloadrust-ac39debeba2b63a39a3833e2d7451f0b1f95b5f2.tar.gz
rust-ac39debeba2b63a39a3833e2d7451f0b1f95b5f2.zip
Move panic safety traits tests
Diffstat (limited to 'library/core/tests')
-rw-r--r--library/core/tests/lib.rs1
-rw-r--r--library/core/tests/panic_safe.rs56
2 files changed, 57 insertions, 0 deletions
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 4db391f3e56..4211d0e95a9 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -78,6 +78,7 @@ mod nonzero;
 mod num;
 mod ops;
 mod option;
+mod panic_safe;
 mod pattern;
 mod ptr;
 mod result;
diff --git a/library/core/tests/panic_safe.rs b/library/core/tests/panic_safe.rs
new file mode 100644
index 00000000000..3104ba539c3
--- /dev/null
+++ b/library/core/tests/panic_safe.rs
@@ -0,0 +1,56 @@
+#![allow(dead_code)]
+
+use std::cell::RefCell;
+use std::panic::{AssertUnwindSafe, UnwindSafe};
+use std::rc::Rc;
+use std::sync::{Arc, Mutex, RwLock};
+
+struct Foo {
+    a: i32,
+}
+
+fn assert<T: UnwindSafe + ?Sized>() {}
+
+#[test]
+fn test_panic_safety_traits() {
+    assert::<i32>();
+    assert::<&i32>();
+    assert::<*mut i32>();
+    assert::<*const i32>();
+    assert::<usize>();
+    assert::<str>();
+    assert::<&str>();
+    assert::<Foo>();
+    assert::<&Foo>();
+    assert::<Vec<i32>>();
+    assert::<String>();
+    assert::<RefCell<i32>>();
+    assert::<Box<i32>>();
+    assert::<Mutex<i32>>();
+    assert::<RwLock<i32>>();
+    assert::<&Mutex<i32>>();
+    assert::<&RwLock<i32>>();
+    assert::<Rc<i32>>();
+    assert::<Arc<i32>>();
+    assert::<Box<[u8]>>();
+
+    {
+        trait Trait: UnwindSafe {}
+        assert::<Box<dyn Trait>>();
+    }
+
+    fn bar<T>() {
+        assert::<Mutex<T>>();
+        assert::<RwLock<T>>();
+    }
+
+    fn baz<T: UnwindSafe>() {
+        assert::<Box<T>>();
+        assert::<Vec<T>>();
+        assert::<RefCell<T>>();
+        assert::<AssertUnwindSafe<T>>();
+        assert::<&AssertUnwindSafe<T>>();
+        assert::<Rc<AssertUnwindSafe<T>>>();
+        assert::<Arc<AssertUnwindSafe<T>>>();
+    }
+}