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