summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs
blob: 8b8e262fb9dcaeb047941cae9a66f7aeabd7ce17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// compile-flags: -Zunleash-the-miri-inside-of-you
// stderr-per-bitwidth
#![allow(const_err)]

use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;

// These only fail during validation (they do not use but just create a reference to a static),
// so they cause an immediate error when *defining* the const.

const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
//~| encountered a reference pointing to a static variable
    static FOO: AtomicUsize = AtomicUsize::new(0);
    unsafe { &*(&FOO as *const _ as *const usize) }
};

// ok some day perhaps
const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
//~| encountered a reference pointing to a static variable
    static FOO: usize = 0;
    &FOO
};

fn main() {}