summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs')
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs
new file mode 100644
index 000000000..8b8e262fb
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs
@@ -0,0 +1,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() {}