]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs
Rollup merge of #98640 - cuviper:stable-rust-analyzer, r=Mark-Simulacrum
[rust.git] / src / test / ui / consts / miri_unleashed / const_refers_to_static2.rs
1 // compile-flags: -Zunleash-the-miri-inside-of-you
2 // stderr-per-bitwidth
3 #![allow(const_err)]
4
5 use std::sync::atomic::AtomicUsize;
6 use std::sync::atomic::Ordering;
7
8 // These only fail during validation (they do not use but just create a reference to a static),
9 // so they cause an immediate error when *defining* the const.
10
11 const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
12 //~| encountered a reference pointing to a static variable
13     static FOO: AtomicUsize = AtomicUsize::new(0);
14     unsafe { &*(&FOO as *const _ as *const usize) }
15 };
16
17 // ok some day perhaps
18 const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
19 //~| encountered a reference pointing to a static variable
20     static FOO: usize = 0;
21     &FOO
22 };
23
24 fn main() {}