]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-17718-static-unsafe-interior.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / issue-17718-static-unsafe-interior.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // pretty-expanded FIXME #23616
12
13 #![feature(core)]
14 #![feature(const_fn)]
15
16
17 use std::marker;
18 use std::cell::UnsafeCell;
19
20 struct MyUnsafePack<T>(UnsafeCell<T>);
21
22 unsafe impl<T: Send> Sync for MyUnsafePack<T> {}
23
24 struct MyUnsafe<T> {
25     value: MyUnsafePack<T>
26 }
27
28 impl<T> MyUnsafe<T> {
29     fn forbidden(&self) {}
30 }
31
32 unsafe impl<T: Send> Sync for MyUnsafe<T> {}
33
34 enum UnsafeEnum<T> {
35     VariantSafe,
36     VariantUnsafe(UnsafeCell<T>)
37 }
38
39 unsafe impl<T: Send> Sync for UnsafeEnum<T> {}
40
41 static STATIC1: UnsafeEnum<isize> = UnsafeEnum::VariantSafe;
42
43 static STATIC2: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
44 const CONST: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
45 static STATIC3: MyUnsafe<isize> = MyUnsafe{value: CONST};
46
47 static STATIC4: &'static MyUnsafePack<isize> = &STATIC2;
48
49 struct Wrap<T> {
50     value: T
51 }
52
53 unsafe impl<T: Send> Sync for Wrap<T> {}
54
55 static UNSAFE: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(2));
56 static WRAPPED_UNSAFE: Wrap<&'static MyUnsafePack<isize>> = Wrap { value: &UNSAFE };
57
58 fn main() {
59     let a = &STATIC1;
60
61     STATIC3.forbidden()
62 }