1 // Copyright 2018 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.
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.
11 // New test for #53818: modifying static memory at compile-time is not allowed.
12 // The test should never succeed.
14 #![feature(const_raw_ptr_deref)]
15 #![feature(const_let)]
17 use std::cell::UnsafeCell;
19 struct Foo(UnsafeCell<u32>);
21 unsafe impl Send for Foo {}
22 unsafe impl Sync for Foo {}
24 static FOO: Foo = Foo(UnsafeCell::new(42));
28 static BAR: () = unsafe {
30 //~^ ERROR statements in statics are unstable (see issue #48821)
31 // This error is caused by a separate bug that the feature gate error is reported
32 // even though the feature gate "const_let" is active.
35 //~^ ERROR calls in statics are limited to constant functions, tuple structs and tuple variants
39 println!("{}", unsafe { *FOO.0.get() });