]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/mod-static-with-const-fn.rs
adjust ui/../mod-static-with-const-fn.rs
[rust.git] / src / test / ui / consts / const-eval / mod-static-with-const-fn.rs
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.
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 // New test for #53818: modifying static memory at compile-time is not allowed.
12 // The test should never succeed.
13
14 #![feature(const_raw_ptr_deref)]
15 #![feature(const_let)]
16
17 use std::cell::UnsafeCell;
18
19 struct Foo(UnsafeCell<u32>);
20
21 unsafe impl Send for Foo {}
22 unsafe impl Sync for Foo {}
23
24 static FOO: Foo = Foo(UnsafeCell::new(42));
25
26 fn foo() {}
27
28 static BAR: () = unsafe {
29     *FOO.0.get() = 5;
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.
33
34     foo();
35     //~^ ERROR calls in statics are limited to constant functions, tuple structs and tuple variants
36 };
37
38 fn main() {
39     println!("{}", unsafe { *FOO.0.get() });
40 }