]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/issue-17718-static-unsafe-interior.rs
New upstream version 1.22.1+dfsg1
[rustc.git] / src / test / run-pass / issue-17718-static-unsafe-interior.rs
CommitLineData
1a4d82fc
JJ
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
c34b1796
AL
11// pretty-expanded FIXME #23616
12
13#![feature(core)]
ea8adc8c 14#![feature(const_unsafe_cell_new)]
c34b1796 15
1a4d82fc
JJ
16use std::marker;
17use std::cell::UnsafeCell;
18
19struct MyUnsafePack<T>(UnsafeCell<T>);
20
21unsafe impl<T: Send> Sync for MyUnsafePack<T> {}
22
23struct MyUnsafe<T> {
24 value: MyUnsafePack<T>
25}
26
27impl<T> MyUnsafe<T> {
28 fn forbidden(&self) {}
29}
30
31unsafe impl<T: Send> Sync for MyUnsafe<T> {}
32
33enum UnsafeEnum<T> {
34 VariantSafe,
35 VariantUnsafe(UnsafeCell<T>)
36}
37
38unsafe impl<T: Send> Sync for UnsafeEnum<T> {}
39
c34b1796 40static STATIC1: UnsafeEnum<isize> = UnsafeEnum::VariantSafe;
1a4d82fc 41
62682a34
SL
42static STATIC2: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
43const CONST: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
c34b1796 44static STATIC3: MyUnsafe<isize> = MyUnsafe{value: CONST};
1a4d82fc 45
c34b1796 46static STATIC4: &'static MyUnsafePack<isize> = &STATIC2;
1a4d82fc
JJ
47
48struct Wrap<T> {
49 value: T
50}
51
52unsafe impl<T: Send> Sync for Wrap<T> {}
53
62682a34 54static UNSAFE: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(2));
c34b1796 55static WRAPPED_UNSAFE: Wrap<&'static MyUnsafePack<isize>> = Wrap { value: &UNSAFE };
1a4d82fc
JJ
56
57fn main() {
58 let a = &STATIC1;
59
60 STATIC3.forbidden()
61}