]> git.proxmox.com Git - rustc.git/blob - tests/ui/consts/const-eval/mod-static-with-const-fn.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / 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_mut_refs)]
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 //~^ ERROR could not evaluate static initializer
18 };
19
20 fn main() {
21 println!("{}", unsafe { *FOO.0.get() });
22 }