2024-01-05 12:18:11 +01:00
|
|
|
//@ run-pass
|
2025-05-12 13:34:46 +02:00
|
|
|
use std::sync::atomic::AtomicU32;
|
2024-01-05 12:18:11 +01:00
|
|
|
|
|
|
|
|
static S: i32 = 0;
|
|
|
|
|
static mut S_MUT: i32 = 0;
|
|
|
|
|
|
|
|
|
|
const C1: &i32 = &S;
|
|
|
|
|
#[allow(unused)]
|
|
|
|
|
const C1_READ: () = {
|
|
|
|
|
assert!(*C1 == 0);
|
|
|
|
|
};
|
2024-05-31 18:48:42 -07:00
|
|
|
const C2: *const i32 = std::ptr::addr_of!(S_MUT);
|
2024-01-05 12:18:11 +01:00
|
|
|
|
2025-05-12 13:34:46 +02:00
|
|
|
static FOO: AtomicU32 = AtomicU32::new(0);
|
|
|
|
|
const NOT_VALID_AS_PATTERN: &'static AtomicU32 = &FOO;
|
|
|
|
|
|
2024-01-05 12:18:11 +01:00
|
|
|
fn main() {
|
|
|
|
|
assert_eq!(*C1, 0);
|
|
|
|
|
assert_eq!(unsafe { *C2 }, 0);
|
|
|
|
|
// Computing this pattern will read from an immutable static. That's fine.
|
|
|
|
|
assert!(matches!(&0, C1));
|
2025-05-12 13:34:46 +02:00
|
|
|
let _val = NOT_VALID_AS_PATTERN;
|
2024-01-05 12:18:11 +01:00
|
|
|
}
|