]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-17718-static-unsafe-interior.rs
388408cbd4da197c5379d38e2036203f7bdec5e1
[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 #![feature(core)]
12
13 use std::marker;
14 use std::cell::UnsafeCell;
15
16 struct MyUnsafePack<T>(UnsafeCell<T>);
17
18 unsafe impl<T: Send> Sync for MyUnsafePack<T> {}
19
20 struct MyUnsafe<T> {
21     value: MyUnsafePack<T>
22 }
23
24 impl<T> MyUnsafe<T> {
25     fn forbidden(&self) {}
26 }
27
28 unsafe impl<T: Send> Sync for MyUnsafe<T> {}
29
30 enum UnsafeEnum<T> {
31     VariantSafe,
32     VariantUnsafe(UnsafeCell<T>)
33 }
34
35 unsafe impl<T: Send> Sync for UnsafeEnum<T> {}
36
37 static STATIC1: UnsafeEnum<int> = UnsafeEnum::VariantSafe;
38
39 static STATIC2: MyUnsafePack<int> = MyUnsafePack(UnsafeCell { value: 1 });
40 const CONST: MyUnsafePack<int> = MyUnsafePack(UnsafeCell { value: 1 });
41 static STATIC3: MyUnsafe<int> = MyUnsafe{value: CONST};
42
43 static STATIC4: &'static MyUnsafePack<int> = &STATIC2;
44
45 struct Wrap<T> {
46     value: T
47 }
48
49 unsafe impl<T: Send> Sync for Wrap<T> {}
50
51 static UNSAFE: MyUnsafePack<int> = MyUnsafePack(UnsafeCell{value: 2});
52 static WRAPPED_UNSAFE: Wrap<&'static MyUnsafePack<int>> = Wrap { value: &UNSAFE };
53
54 fn main() {
55     let a = &STATIC1;
56
57     STATIC3.forbidden()
58 }