]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/mod-static-with-const-fn.rs
Auto merge of #81132 - bugadani:map-prealloc, r=matthewjasper
[rust.git] / src / test / ui / consts / const-eval / mod-static-with-const-fn.rs
1 // New test for #53818: modifying static memory at compile-time is not allowed.
2 // The test should never compile successfully
3
4 #![feature(const_raw_ptr_deref)]
5
6 use std::cell::UnsafeCell;
7
8 struct Foo(UnsafeCell<u32>);
9
10 unsafe impl Send for Foo {}
11 unsafe impl Sync for Foo {}
12
13 static FOO: Foo = Foo(UnsafeCell::new(42));
14
15 static BAR: () = unsafe {
16     *FOO.0.get() = 5;
17     //~^ mutation through a reference
18 };
19
20 fn main() {
21     println!("{}", unsafe { *FOO.0.get() });
22 }