Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI to unit test for those using Cell/RefCell/UnsafeCell #76454

Merged
merged 14 commits into from
Sep 28, 2020
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ mod nonzero;
mod num;
mod ops;
mod option;
mod panic_safe;
poliorcetics marked this conversation as resolved.
Show resolved Hide resolved
mod pattern;
mod ptr;
mod result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// run-pass
#![allow(dead_code)]

use std::panic::{UnwindSafe, AssertUnwindSafe};
use std::cell::RefCell;
use std::sync::{Mutex, RwLock, Arc};
use std::panic::{AssertUnwindSafe, UnwindSafe};
use std::rc::Rc;
use std::sync::{Arc, Mutex, RwLock};

struct Foo { a: i32 }
struct Foo {
a: i32,
}

fn assert<T: UnwindSafe + ?Sized>() {}

fn main() {
#[test]
fn test_panic_safety_traits() {
assert::<i32>();
assert::<&i32>();
assert::<*mut i32>();
Expand All @@ -32,13 +34,16 @@ fn main() {
assert::<Arc<i32>>();
assert::<Box<[u8]>>();

trait Trait: UnwindSafe {}
assert::<Box<dyn Trait>>();
{
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>>();
Expand Down