1
Fork 0

Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matklad

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

Helps with #76268.

I'm working on all files using `Cell` and moving them to unit tests when possible.

r? @matklad
This commit is contained in:
Ralf Jung 2020-09-28 18:39:39 +02:00 committed by GitHub
commit 734c57d45c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 667 additions and 687 deletions

View file

@ -411,3 +411,6 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
pub fn resume_unwind(payload: Box<dyn Any + Send>) -> ! {
panicking::rust_panic_without_hook(payload)
}
#[cfg(test)]
mod tests;

View file

@ -0,0 +1,56 @@
#![allow(dead_code)]
use crate::cell::RefCell;
use crate::panic::{AssertUnwindSafe, UnwindSafe};
use crate::rc::Rc;
use crate::sync::{Arc, Mutex, RwLock};
struct Foo {
a: i32,
}
fn assert<T: UnwindSafe + ?Sized>() {}
#[test]
fn 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>>>();
}
}