]> git.lizzy.rs Git - rust.git/blob - src/test/ui/statics/issue-17718-static-unsafe-interior.rs
Move some tests to more reasonable directories
[rust.git] / src / test / ui / statics / issue-17718-static-unsafe-interior.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 #![allow(unused_imports)]
5 // pretty-expanded FIXME #23616
6
7 use std::marker;
8 use std::cell::UnsafeCell;
9
10 struct MyUnsafePack<T>(UnsafeCell<T>);
11
12 unsafe impl<T: Send> Sync for MyUnsafePack<T> {}
13
14 struct MyUnsafe<T> {
15     value: MyUnsafePack<T>
16 }
17
18 impl<T> MyUnsafe<T> {
19     fn forbidden(&self) {}
20 }
21
22 unsafe impl<T: Send> Sync for MyUnsafe<T> {}
23
24 enum UnsafeEnum<T> {
25     VariantSafe,
26     VariantUnsafe(UnsafeCell<T>)
27 }
28
29 unsafe impl<T: Send> Sync for UnsafeEnum<T> {}
30
31 static STATIC1: UnsafeEnum<isize> = UnsafeEnum::VariantSafe;
32
33 static STATIC2: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
34 const CONST: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
35 static STATIC3: MyUnsafe<isize> = MyUnsafe{value: CONST};
36
37 static STATIC4: &'static MyUnsafePack<isize> = &STATIC2;
38
39 struct Wrap<T> {
40     value: T
41 }
42
43 unsafe impl<T: Send> Sync for Wrap<T> {}
44
45 static UNSAFE: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(2));
46 static WRAPPED_UNSAFE: Wrap<&'static MyUnsafePack<isize>> = Wrap { value: &UNSAFE };
47
48 fn main() {
49     let a = &STATIC1;
50
51     STATIC3.forbidden()
52 }