summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/miri_unleashed
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/consts/miri_unleashed')
-rw-r--r--src/test/ui/consts/miri_unleashed/abi-mismatch.rs19
-rw-r--r--src/test/ui/consts/miri_unleashed/abi-mismatch.stderr23
-rw-r--r--src/test/ui/consts/miri_unleashed/assoc_const.rs32
-rw-r--r--src/test/ui/consts/miri_unleashed/assoc_const.stderr42
-rw-r--r--src/test/ui/consts/miri_unleashed/assoc_const_2.rs30
-rw-r--r--src/test/ui/consts/miri_unleashed/assoc_const_2.stderr24
-rw-r--r--src/test/ui/consts/miri_unleashed/auxiliary/static_cross_crate.rs3
-rw-r--r--src/test/ui/consts/miri_unleashed/box.rs13
-rw-r--r--src/test/ui/consts/miri_unleashed/box.stderr32
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static.rs31
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr100
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static2.32bit.stderr38
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static2.64bit.stderr38
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs24
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr192
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr192
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs82
-rw-r--r--src/test/ui/consts/miri_unleashed/drop.rs18
-rw-r--r--src/test/ui/consts/miri_unleashed/drop.stderr25
-rw-r--r--src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs28
-rw-r--r--src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr11
-rw-r--r--src/test/ui/consts/miri_unleashed/inline_asm.rs14
-rw-r--r--src/test/ui/consts/miri_unleashed/inline_asm.stderr17
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references.rs37
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references.stderr37
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr54
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr54
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references_err.rs38
-rw-r--r--src/test/ui/consts/miri_unleashed/mutating_global.rs16
-rw-r--r--src/test/ui/consts/miri_unleashed/mutating_global.stderr9
-rw-r--r--src/test/ui/consts/miri_unleashed/non_const_fn.rs13
-rw-r--r--src/test/ui/consts/miri_unleashed/non_const_fn.stderr17
-rw-r--r--src/test/ui/consts/miri_unleashed/ptr_arith.rs22
-rw-r--r--src/test/ui/consts/miri_unleashed/ptr_arith.stderr26
-rw-r--r--src/test/ui/consts/miri_unleashed/raw_mutable_const.rs10
-rw-r--r--src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr16
-rw-r--r--src/test/ui/consts/miri_unleashed/slice_eq.rs17
-rw-r--r--src/test/ui/consts/miri_unleashed/tls.rs24
-rw-r--r--src/test/ui/consts/miri_unleashed/tls.stderr28
39 files changed, 1446 insertions, 0 deletions
diff --git a/src/test/ui/consts/miri_unleashed/abi-mismatch.rs b/src/test/ui/consts/miri_unleashed/abi-mismatch.rs
new file mode 100644
index 000000000..3360e9cac
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/abi-mismatch.rs
@@ -0,0 +1,19 @@
+// Checks that we report ABI mismatches for "const extern fn"
+// compile-flags: -Z unleash-the-miri-inside-of-you
+
+#![feature(const_extern_fn)]
+#![allow(const_err)]
+
+const extern "C" fn c_fn() {}
+
+const fn call_rust_fn(my_fn: extern "Rust" fn()) {
+ my_fn();
+ //~^ ERROR could not evaluate static initializer
+ //~| NOTE calling a function with calling convention C using calling convention Rust
+ //~| NOTE inside `call_rust_fn`
+}
+
+static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
+//~^ NOTE inside `VAL`
+
+fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/abi-mismatch.stderr b/src/test/ui/consts/miri_unleashed/abi-mismatch.stderr
new file mode 100644
index 000000000..aaba19c2c
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/abi-mismatch.stderr
@@ -0,0 +1,23 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/abi-mismatch.rs:10:5
+ |
+LL | my_fn();
+ | ^^^^^^^
+ | |
+ | calling a function with calling convention C using calling convention Rust
+ | inside `call_rust_fn` at $DIR/abi-mismatch.rs:10:5
+...
+LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
+ | --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:16:18
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/abi-mismatch.rs:10:5
+ |
+LL | my_fn();
+ | ^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const.rs b/src/test/ui/consts/miri_unleashed/assoc_const.rs
new file mode 100644
index 000000000..5f520c2cf
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/assoc_const.rs
@@ -0,0 +1,32 @@
+// build-fail
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+#![allow(const_err)]
+
+// a test demonstrating why we do need to run static const qualification on associated constants
+// instead of just checking the final constant
+
+trait Foo<T> {
+ const X: T;
+}
+
+trait Bar<T, U: Foo<T>> {
+ const F: u32 = (U::X, 42).1;
+}
+
+impl Foo<u32> for () {
+ const X: u32 = 42;
+}
+impl Foo<Vec<u32>> for String {
+ const X: Vec<u32> = Vec::new();
+}
+
+impl Bar<u32, ()> for () {}
+impl Bar<Vec<u32>, String> for String {}
+
+fn main() {
+ // this is fine, but would have been forbidden by the static checks on `F`
+ let x = <() as Bar<u32, ()>>::F;
+ // this test only causes errors due to the line below, so post-monomorphization
+ let y = <String as Bar<Vec<u32>, String>>::F; //~ ERROR erroneous constant
+}
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const.stderr b/src/test/ui/consts/miri_unleashed/assoc_const.stderr
new file mode 100644
index 000000000..1f82ac827
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/assoc_const.stderr
@@ -0,0 +1,42 @@
+error[E0080]: erroneous constant used
+ --> $DIR/assoc_const.rs:31:13
+ |
+LL | let y = <String as Bar<Vec<u32>, String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/assoc_const.rs:14:20
+ |
+LL | const F: u32 = (U::X, 42).1;
+ | ^^^^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
+Future incompatibility report: Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+ |
+LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | calling non-const function `<Vec<u32> as Drop>::drop`
+ | inside `std::ptr::drop_in_place::<Vec<u32>> - shim(Some(Vec<u32>))` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+ | inside `std::ptr::drop_in_place::<(Vec<u32>, u32)> - shim(Some((Vec<u32>, u32)))` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+ | inside `<String as Bar<Vec<u32>, String>>::F` at $DIR/assoc_const.rs:14:31
+ |
+ ::: $DIR/assoc_const.rs:14:5
+ |
+LL | const F: u32 = (U::X, 42).1;
+ | ------------
+ |
+note: the lint level is defined here
+ --> $DIR/assoc_const.rs:4:10
+ |
+LL | #![allow(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const_2.rs b/src/test/ui/consts/miri_unleashed/assoc_const_2.rs
new file mode 100644
index 000000000..30dd2a515
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/assoc_const_2.rs
@@ -0,0 +1,30 @@
+// build-fail
+
+#![allow(const_err)]
+
+// a test demonstrating that const qualification cannot prevent monomorphization time errors
+
+trait Foo {
+ const X: u32;
+}
+
+trait Bar<U: Foo> {
+ const F: u32 = 100 / U::X;
+}
+
+impl Foo for () {
+ const X: u32 = 42;
+}
+
+impl Foo for String {
+ const X: u32 = 0;
+}
+
+impl Bar<()> for () {}
+impl Bar<String> for String {}
+
+fn main() {
+ let x = <() as Bar<()>>::F;
+ // this test only causes errors due to the line below, so post-monomorphization
+ let y = <String as Bar<String>>::F; //~ ERROR erroneous constant
+}
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr b/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr
new file mode 100644
index 000000000..cbf02199f
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr
@@ -0,0 +1,24 @@
+error[E0080]: erroneous constant used
+ --> $DIR/assoc_const_2.rs:29:13
+ |
+LL | let y = <String as Bar<String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
+Future incompatibility report: Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $DIR/assoc_const_2.rs:12:20
+ |
+LL | const F: u32 = 100 / U::X;
+ | ------------ ^^^^^^^^^^ attempt to divide `100_u32` by zero
+ |
+note: the lint level is defined here
+ --> $DIR/assoc_const_2.rs:3:10
+ |
+LL | #![allow(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
diff --git a/src/test/ui/consts/miri_unleashed/auxiliary/static_cross_crate.rs b/src/test/ui/consts/miri_unleashed/auxiliary/static_cross_crate.rs
new file mode 100644
index 000000000..4fc6ae66a
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/auxiliary/static_cross_crate.rs
@@ -0,0 +1,3 @@
+pub static mut ZERO: [u8; 1] = [0];
+pub static ZERO_REF: &[u8; 1] = unsafe { &ZERO };
+pub static mut OPT_ZERO: Option<u8> = Some(0);
diff --git a/src/test/ui/consts/miri_unleashed/box.rs b/src/test/ui/consts/miri_unleashed/box.rs
new file mode 100644
index 000000000..32796c672
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/box.rs
@@ -0,0 +1,13 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(box_syntax)]
+#![allow(const_err)]
+
+use std::mem::ManuallyDrop;
+
+fn main() {}
+
+static TEST_BAD: &mut i32 = {
+ &mut *(box 0)
+ //~^ ERROR could not evaluate static initializer
+ //~| NOTE calling non-const function `alloc::alloc::exchange_malloc`
+};
diff --git a/src/test/ui/consts/miri_unleashed/box.stderr b/src/test/ui/consts/miri_unleashed/box.stderr
new file mode 100644
index 000000000..05d9858dc
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/box.stderr
@@ -0,0 +1,32 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/box.rs:10:11
+ |
+LL | &mut *(box 0)
+ | ^^^^^^^ calling non-const function `alloc::alloc::exchange_malloc`
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/box.rs:10:11
+ |
+LL | &mut *(box 0)
+ | ^^^^^^^
+help: skipping check for `const_mut_refs` feature
+ --> $DIR/box.rs:10:16
+ |
+LL | &mut *(box 0)
+ | ^
+help: skipping check for `const_mut_refs` feature
+ --> $DIR/box.rs:10:5
+ |
+LL | &mut *(box 0)
+ | ^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/box.rs:10:5
+ |
+LL | &mut *(box 0)
+ | ^^^^^^^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs
new file mode 100644
index 000000000..c9dc1de51
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs
@@ -0,0 +1,31 @@
+// build-fail
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![allow(const_err)]
+
+use std::sync::atomic::AtomicUsize;
+use std::sync::atomic::Ordering;
+
+// These fail during CTFE (as they read a static), so they only cause an error
+// when *using* the const.
+
+const MUTATE_INTERIOR_MUT: usize = {
+ static FOO: AtomicUsize = AtomicUsize::new(0);
+ FOO.fetch_add(1, Ordering::Relaxed)
+};
+
+const READ_INTERIOR_MUT: usize = {
+ static FOO: AtomicUsize = AtomicUsize::new(0);
+ unsafe { *(&FOO as *const _ as *const usize) }
+};
+
+static mut MUTABLE: u32 = 0;
+const READ_MUT: u32 = unsafe { MUTABLE };
+
+fn main() {
+ MUTATE_INTERIOR_MUT;
+ //~^ ERROR: erroneous constant used
+ READ_INTERIOR_MUT;
+ //~^ ERROR: erroneous constant used
+ READ_MUT;
+ //~^ ERROR: erroneous constant used
+}
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr
new file mode 100644
index 000000000..fa2088124
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr
@@ -0,0 +1,100 @@
+error[E0080]: erroneous constant used
+ --> $DIR/const_refers_to_static.rs:25:5
+ |
+LL | MUTATE_INTERIOR_MUT;
+ | ^^^^^^^^^^^^^^^^^^^ referenced constant has errors
+
+error[E0080]: erroneous constant used
+ --> $DIR/const_refers_to_static.rs:27:5
+ |
+LL | READ_INTERIOR_MUT;
+ | ^^^^^^^^^^^^^^^^^ referenced constant has errors
+
+error[E0080]: erroneous constant used
+ --> $DIR/const_refers_to_static.rs:29:5
+ |
+LL | READ_MUT;
+ | ^^^^^^^^ referenced constant has errors
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:13:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:13:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:18:17
+ |
+LL | unsafe { *(&FOO as *const _ as *const usize) }
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:22:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:22:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^
+
+error: aborting due to 3 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
+Future incompatibility report: Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static.rs:13:5
+ |
+LL | const MUTATE_INTERIOR_MUT: usize = {
+ | --------------------------------
+LL | static FOO: AtomicUsize = AtomicUsize::new(0);
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `AtomicUsize::fetch_add`
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static.rs:3:10
+ |
+LL | #![allow(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
+Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static.rs:18:14
+ |
+LL | const READ_INTERIOR_MUT: usize = {
+ | ------------------------------
+LL | static FOO: AtomicUsize = AtomicUsize::new(0);
+LL | unsafe { *(&FOO as *const _ as *const usize) }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static.rs:3:10
+ |
+LL | #![allow(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
+Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static.rs:22:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ------------------- ^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static.rs:3:10
+ |
+LL | #![allow(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.32bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.32bit.stderr
new file mode 100644
index 000000000..b3ad81e49
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.32bit.stderr
@@ -0,0 +1,38 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static2.rs:11:1
+ |
+LL | const REF_INTERIOR_MUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 4, align: 4) {
+ ╾─alloc1──╼ │ ╾──╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static2.rs:18:1
+ |
+LL | const READ_IMMUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 4, align: 4) {
+ ╾─alloc2──╼ │ ╾──╼
+ }
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static2.rs:14:18
+ |
+LL | unsafe { &*(&FOO as *const _ as *const usize) }
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static2.rs:21:6
+ |
+LL | &FOO
+ | ^^^
+
+error: aborting due to 2 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.64bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.64bit.stderr
new file mode 100644
index 000000000..24bd07092
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.64bit.stderr
@@ -0,0 +1,38 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static2.rs:11:1
+ |
+LL | const REF_INTERIOR_MUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 8) {
+ ╾───────alloc1────────╼ │ ╾──────╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static2.rs:18:1
+ |
+LL | const READ_IMMUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 8) {
+ ╾───────alloc2────────╼ │ ╾──────╼
+ }
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static2.rs:14:18
+ |
+LL | unsafe { &*(&FOO as *const _ as *const usize) }
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static2.rs:21:6
+ |
+LL | &FOO
+ | ^^^
+
+error: aborting due to 2 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
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() {}
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr
new file mode 100644
index 000000000..20a96b57f
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr
@@ -0,0 +1,192 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static_cross_crate.rs:12:1
+ |
+LL | const SLICE_MUT: &[u8; 1] = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 4, align: 4) {
+ ╾─alloc1──╼ │ ╾──╼
+ }
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:40:9
+ |
+LL | SLICE_MUT => true,
+ | ^^^^^^^^^
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static_cross_crate.rs:17:1
+ |
+LL | const U8_MUT: &u8 = {
+ | ^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 4, align: 4) {
+ ╾─alloc1──╼ │ ╾──╼
+ }
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:49:9
+ |
+LL | U8_MUT => true,
+ | ^^^^^^
+
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static_cross_crate.rs:25:15
+ |
+LL | const U8_MUT2: &u8 = {
+ | ------------------
+LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static_cross_crate.rs:23:8
+ |
+LL | #[warn(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:60:9
+ |
+LL | U8_MUT2 => true,
+ | ^^^^^^^
+
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | const U8_MUT3: &u8 = {
+ | ------------------
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static_cross_crate.rs:30:8
+ |
+LL | #[warn(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:68:9
+ |
+LL | U8_MUT3 => true,
+ | ^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:40:9
+ |
+LL | SLICE_MUT => true,
+ | ^^^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:49:9
+ |
+LL | U8_MUT => true,
+ | ^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:60:9
+ |
+LL | U8_MUT2 => true,
+ | ^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:68:9
+ |
+LL | U8_MUT3 => true,
+ | ^^^^^^^
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:14:15
+ |
+LL | unsafe { &static_cross_crate::ZERO }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:14:15
+ |
+LL | unsafe { &static_cross_crate::ZERO }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ |
+LL | unsafe { &static_cross_crate::ZERO[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ |
+LL | unsafe { &static_cross_crate::ZERO[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ |
+LL | unsafe { &static_cross_crate::ZERO[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:25:17
+ |
+LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 10 previous errors; 3 warnings emitted
+
+For more information about this error, try `rustc --explain E0080`.
+Future incompatibility report: Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static_cross_crate.rs:25:15
+ |
+LL | const U8_MUT2: &u8 = {
+ | ------------------
+LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static_cross_crate.rs:23:8
+ |
+LL | #[warn(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
+Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | const U8_MUT3: &u8 = {
+ | ------------------
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static_cross_crate.rs:30:8
+ |
+LL | #[warn(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr
new file mode 100644
index 000000000..dfa0f76ba
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr
@@ -0,0 +1,192 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static_cross_crate.rs:12:1
+ |
+LL | const SLICE_MUT: &[u8; 1] = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 8) {
+ ╾───────alloc1────────╼ │ ╾──────╼
+ }
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:40:9
+ |
+LL | SLICE_MUT => true,
+ | ^^^^^^^^^
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static_cross_crate.rs:17:1
+ |
+LL | const U8_MUT: &u8 = {
+ | ^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 8) {
+ ╾───────alloc1────────╼ │ ╾──────╼
+ }
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:49:9
+ |
+LL | U8_MUT => true,
+ | ^^^^^^
+
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static_cross_crate.rs:25:15
+ |
+LL | const U8_MUT2: &u8 = {
+ | ------------------
+LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static_cross_crate.rs:23:8
+ |
+LL | #[warn(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:60:9
+ |
+LL | U8_MUT2 => true,
+ | ^^^^^^^
+
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | const U8_MUT3: &u8 = {
+ | ------------------
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static_cross_crate.rs:30:8
+ |
+LL | #[warn(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:68:9
+ |
+LL | U8_MUT3 => true,
+ | ^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:40:9
+ |
+LL | SLICE_MUT => true,
+ | ^^^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:49:9
+ |
+LL | U8_MUT => true,
+ | ^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:60:9
+ |
+LL | U8_MUT2 => true,
+ | ^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:68:9
+ |
+LL | U8_MUT3 => true,
+ | ^^^^^^^
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:14:15
+ |
+LL | unsafe { &static_cross_crate::ZERO }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:14:15
+ |
+LL | unsafe { &static_cross_crate::ZERO }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ |
+LL | unsafe { &static_cross_crate::ZERO[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ |
+LL | unsafe { &static_cross_crate::ZERO[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ |
+LL | unsafe { &static_cross_crate::ZERO[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:25:17
+ |
+LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 10 previous errors; 3 warnings emitted
+
+For more information about this error, try `rustc --explain E0080`.
+Future incompatibility report: Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static_cross_crate.rs:25:15
+ |
+LL | const U8_MUT2: &u8 = {
+ | ------------------
+LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static_cross_crate.rs:23:8
+ |
+LL | #[warn(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
+Future breakage diagnostic:
+warning: any use of this value will cause an error
+ --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ |
+LL | const U8_MUT3: &u8 = {
+ | ------------------
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+ |
+note: the lint level is defined here
+ --> $DIR/const_refers_to_static_cross_crate.rs:30:8
+ |
+LL | #[warn(const_err)]
+ | ^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
new file mode 100644
index 000000000..4638d73fc
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
@@ -0,0 +1,82 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// aux-build:static_cross_crate.rs
+// stderr-per-bitwidth
+#![allow(const_err)]
+
+#![feature(exclusive_range_pattern, half_open_range_patterns)]
+
+extern crate static_cross_crate;
+
+// Sneaky: reference to a mutable static.
+// Allowing this would be a disaster for pattern matching, we could violate exhaustiveness checking!
+const SLICE_MUT: &[u8; 1] = { //~ ERROR undefined behavior to use this value
+//~| encountered a reference pointing to a static variable
+ unsafe { &static_cross_crate::ZERO }
+};
+
+const U8_MUT: &u8 = { //~ ERROR undefined behavior to use this value
+//~| encountered a reference pointing to a static variable
+ unsafe { &static_cross_crate::ZERO[0] }
+};
+
+// Also test indirection that reads from other static. This causes a const_err.
+#[warn(const_err)]
+const U8_MUT2: &u8 = {
+ unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ //~^ WARN [const_err]
+ //~| constant accesses static
+ //~| WARN this was previously accepted by the compiler but is being phased out
+};
+#[warn(const_err)]
+const U8_MUT3: &u8 = {
+ unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ //~^ WARN [const_err]
+ //~| constant accesses static
+ //~| WARN this was previously accepted by the compiler but is being phased out
+};
+
+pub fn test(x: &[u8; 1]) -> bool {
+ match x {
+ SLICE_MUT => true,
+ //~^ ERROR could not evaluate constant pattern
+ //~| ERROR could not evaluate constant pattern
+ &[1..] => false,
+ }
+}
+
+pub fn test2(x: &u8) -> bool {
+ match x {
+ U8_MUT => true,
+ //~^ ERROR could not evaluate constant pattern
+ //~| ERROR could not evaluate constant pattern
+ &(1..) => false,
+ }
+}
+
+// We need to use these *in a pattern* to trigger the failure... likely because
+// the errors above otherwise stop compilation too early?
+pub fn test3(x: &u8) -> bool {
+ match x {
+ U8_MUT2 => true,
+ //~^ ERROR could not evaluate constant pattern
+ //~| ERROR could not evaluate constant pattern
+ &(1..) => false,
+ }
+}
+pub fn test4(x: &u8) -> bool {
+ match x {
+ U8_MUT3 => true,
+ //~^ ERROR could not evaluate constant pattern
+ //~| ERROR could not evaluate constant pattern
+ &(1..) => false,
+ }
+}
+
+fn main() {
+ unsafe {
+ static_cross_crate::ZERO[0] = 1;
+ }
+ // Now the pattern is not exhaustive any more!
+ test(&[0]);
+ test2(&0);
+}
diff --git a/src/test/ui/consts/miri_unleashed/drop.rs b/src/test/ui/consts/miri_unleashed/drop.rs
new file mode 100644
index 000000000..4afa954d9
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/drop.rs
@@ -0,0 +1,18 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// error-pattern: calling non-const function `<Vec<i32> as Drop>::drop`
+#![allow(const_err)]
+
+use std::mem::ManuallyDrop;
+
+fn main() {}
+
+static TEST_OK: () = {
+ let v: Vec<i32> = Vec::new();
+ let _v = ManuallyDrop::new(v);
+};
+
+// Make sure we catch executing bad drop functions.
+// The actual error is tested by the error-pattern above.
+static TEST_BAD: () = {
+ let _v: Vec<i32> = Vec::new();
+};
diff --git a/src/test/ui/consts/miri_unleashed/drop.stderr b/src/test/ui/consts/miri_unleashed/drop.stderr
new file mode 100644
index 000000000..36db6b786
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/drop.stderr
@@ -0,0 +1,25 @@
+error[E0080]: could not evaluate static initializer
+ --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+ |
+LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | calling non-const function `<Vec<i32> as Drop>::drop`
+ | inside `std::ptr::drop_in_place::<Vec<i32>> - shim(Some(Vec<i32>))` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+ |
+ ::: $DIR/drop.rs:18:1
+ |
+LL | };
+ | - inside `TEST_BAD` at $DIR/drop.rs:18:1
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/drop.rs:17:9
+ |
+LL | let _v: Vec<i32> = Vec::new();
+ | ^^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs
new file mode 100644
index 000000000..8b17f6885
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs
@@ -0,0 +1,28 @@
+#![allow(const_err)]
+
+// a test demonstrating why we do need to run static const qualification on associated constants
+// instead of just checking the final constant
+
+trait Foo<T> {
+ const X: T;
+}
+
+trait Bar<T, U: Foo<T>> {
+ const F: u32 = (U::X, 42).1; //~ ERROR destructors cannot be evaluated at compile-time
+}
+
+impl Foo<u32> for () {
+ const X: u32 = 42;
+}
+
+impl Foo<Vec<u32>> for String {
+ const X: Vec<u32> = Vec::new();
+}
+
+impl Bar<u32, ()> for () {}
+impl Bar<Vec<u32>, String> for String {}
+
+fn main() {
+ let x = <() as Bar<u32, ()>>::F;
+ let y = <String as Bar<Vec<u32>, String>>::F;
+}
diff --git a/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr
new file mode 100644
index 000000000..0b6cb2fab
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr
@@ -0,0 +1,11 @@
+error[E0493]: destructors cannot be evaluated at compile-time
+ --> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:11:20
+ |
+LL | const F: u32 = (U::X, 42).1;
+ | ^^^^^^^^^^ - value is dropped here
+ | |
+ | constants cannot evaluate destructors
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0493`.
diff --git a/src/test/ui/consts/miri_unleashed/inline_asm.rs b/src/test/ui/consts/miri_unleashed/inline_asm.rs
new file mode 100644
index 000000000..697117033
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/inline_asm.rs
@@ -0,0 +1,14 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// only-x86_64
+#![allow(const_err)]
+
+use std::arch::asm;
+
+fn main() {}
+
+// Make sure we catch executing inline assembly.
+static TEST_BAD: () = {
+ unsafe { asm!("nop"); }
+ //~^ ERROR could not evaluate static initializer
+ //~| NOTE inline assembly is not supported
+};
diff --git a/src/test/ui/consts/miri_unleashed/inline_asm.stderr b/src/test/ui/consts/miri_unleashed/inline_asm.stderr
new file mode 100644
index 000000000..595b859cb
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/inline_asm.stderr
@@ -0,0 +1,17 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/inline_asm.rs:11:14
+ |
+LL | unsafe { asm!("nop"); }
+ | ^^^^^^^^^^^ inline assembly is not supported
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/inline_asm.rs:11:14
+ |
+LL | unsafe { asm!("nop"); }
+ | ^^^^^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references.rs b/src/test/ui/consts/miri_unleashed/mutable_references.rs
new file mode 100644
index 000000000..ca927ef4a
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/mutable_references.rs
@@ -0,0 +1,37 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![allow(const_err)]
+
+use std::cell::UnsafeCell;
+
+// a test demonstrating what things we could allow with a smarter const qualification
+
+// this is fine because is not possible to mutate through an immutable reference.
+static FOO: &&mut u32 = &&mut 42;
+
+// this is fine because accessing an immutable static `BAR` is equivalent to accessing `*&BAR`
+// which puts the mutable reference behind an immutable one.
+static BAR: &mut () = &mut ();
+
+struct Foo<T>(T);
+
+// this is fine for the same reason as `BAR`.
+static BOO: &mut Foo<()> = &mut Foo(());
+
+// interior mutability is fine
+struct Meh {
+ x: &'static UnsafeCell<i32>,
+}
+unsafe impl Sync for Meh {}
+static MEH: Meh = Meh {
+ x: &UnsafeCell::new(42),
+};
+
+// this is fine for the same reason as `BAR`.
+static OH_YES: &mut i32 = &mut 42;
+
+fn main() {
+ unsafe {
+ *MEH.x.get() = 99;
+ }
+ *OH_YES = 99; //~ ERROR cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
+}
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references.stderr b/src/test/ui/consts/miri_unleashed/mutable_references.stderr
new file mode 100644
index 000000000..c6180c1e0
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/mutable_references.stderr
@@ -0,0 +1,37 @@
+error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
+ --> $DIR/mutable_references.rs:36:5
+ |
+LL | *OH_YES = 99;
+ | ^^^^^^^^^^^^ cannot assign
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:9:26
+ |
+LL | static FOO: &&mut u32 = &&mut 42;
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:13:23
+ |
+LL | static BAR: &mut () = &mut ();
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:18:28
+ |
+LL | static BOO: &mut Foo<()> = &mut Foo(());
+ | ^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:26:8
+ |
+LL | x: &UnsafeCell::new(42),
+ | ^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:30:27
+ |
+LL | static OH_YES: &mut i32 = &mut 42;
+ | ^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0594`.
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr b/src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr
new file mode 100644
index 000000000..7ea35f70d
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr
@@ -0,0 +1,54 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/mutable_references_err.rs:17:1
+ |
+LL | const MUH: Meh = Meh {
+ | ^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in a `const`
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 4, align: 4) {
+ ╾─alloc3──╼ │ ╾──╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/mutable_references_err.rs:27:1
+ |
+LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>.x: encountered `UnsafeCell` in a `const`
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 4) {
+ ╾─alloc7──╼ ╾─alloc8──╼ │ ╾──╼╾──╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/mutable_references_err.rs:31:1
+ |
+LL | const BLUNT: &mut i32 = &mut 42;
+ | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const`
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 4, align: 4) {
+ ╾─alloc10─╼ │ ╾──╼
+ }
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references_err.rs:18:8
+ |
+LL | x: &UnsafeCell::new(42),
+ | ^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references_err.rs:27:27
+ |
+LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references_err.rs:31:25
+ |
+LL | const BLUNT: &mut i32 = &mut 42;
+ | ^^^^^^^
+
+error: aborting due to 3 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr b/src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr
new file mode 100644
index 000000000..5ad398930
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr
@@ -0,0 +1,54 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/mutable_references_err.rs:17:1
+ |
+LL | const MUH: Meh = Meh {
+ | ^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in a `const`
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 8) {
+ ╾───────alloc3────────╼ │ ╾──────╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/mutable_references_err.rs:27:1
+ |
+LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>.x: encountered `UnsafeCell` in a `const`
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 16, align: 8) {
+ ╾───────alloc7────────╼ ╾───────alloc8────────╼ │ ╾──────╼╾──────╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/mutable_references_err.rs:31:1
+ |
+LL | const BLUNT: &mut i32 = &mut 42;
+ | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const`
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 8) {
+ ╾───────alloc10───────╼ │ ╾──────╼
+ }
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references_err.rs:18:8
+ |
+LL | x: &UnsafeCell::new(42),
+ | ^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references_err.rs:27:27
+ |
+LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references_err.rs:31:25
+ |
+LL | const BLUNT: &mut i32 = &mut 42;
+ | ^^^^^^^
+
+error: aborting due to 3 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_err.rs b/src/test/ui/consts/miri_unleashed/mutable_references_err.rs
new file mode 100644
index 000000000..722b9cf94
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/mutable_references_err.rs
@@ -0,0 +1,38 @@
+// stderr-per-bitwidth
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+#![allow(const_err)]
+
+use std::cell::UnsafeCell;
+
+// this test ensures that our mutability story is sound
+
+struct Meh {
+ x: &'static UnsafeCell<i32>,
+}
+unsafe impl Sync for Meh {}
+
+// the following will never be ok! no interior mut behind consts, because
+// all allocs interned here will be marked immutable.
+const MUH: Meh = Meh { //~ ERROR: it is undefined behavior to use this value
+ x: &UnsafeCell::new(42),
+};
+
+struct Synced {
+ x: UnsafeCell<i32>,
+}
+unsafe impl Sync for Synced {}
+
+// Make sure we also catch this behind a type-erased `dyn Trait` reference.
+const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
+//~^ ERROR: it is undefined behavior to use this value
+
+// Make sure we also catch mutable references.
+const BLUNT: &mut i32 = &mut 42;
+//~^ ERROR: it is undefined behavior to use this value
+
+fn main() {
+ unsafe {
+ *MUH.x.get() = 99;
+ }
+}
diff --git a/src/test/ui/consts/miri_unleashed/mutating_global.rs b/src/test/ui/consts/miri_unleashed/mutating_global.rs
new file mode 100644
index 000000000..902fe0aa1
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/mutating_global.rs
@@ -0,0 +1,16 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![allow(const_err)]
+
+// Make sure we cannot mutate globals.
+
+static mut GLOBAL: i32 = 0;
+
+static MUTATING_GLOBAL: () = {
+ unsafe {
+ GLOBAL = 99
+ //~^ ERROR could not evaluate static initializer
+ //~| NOTE modifying a static's initial value
+ }
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/mutating_global.stderr b/src/test/ui/consts/miri_unleashed/mutating_global.stderr
new file mode 100644
index 000000000..ba9dd5619
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/mutating_global.stderr
@@ -0,0 +1,9 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/mutating_global.rs:10:9
+ |
+LL | GLOBAL = 99
+ | ^^^^^^^^^^^ modifying a static's initial value from another static's initializer
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/non_const_fn.rs b/src/test/ui/consts/miri_unleashed/non_const_fn.rs
new file mode 100644
index 000000000..70da94df7
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/non_const_fn.rs
@@ -0,0 +1,13 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+#![allow(const_err)]
+
+// A test demonstrating that we prevent calling non-const fn during CTFE.
+
+fn foo() {}
+
+static C: () = foo();
+//~^ ERROR could not evaluate static initializer
+//~| NOTE calling non-const function `foo`
+
+fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/non_const_fn.stderr b/src/test/ui/consts/miri_unleashed/non_const_fn.stderr
new file mode 100644
index 000000000..3e9658ad8
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/non_const_fn.stderr
@@ -0,0 +1,17 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/non_const_fn.rs:9:16
+ |
+LL | static C: () = foo();
+ | ^^^^^ calling non-const function `foo`
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/non_const_fn.rs:9:16
+ |
+LL | static C: () = foo();
+ | ^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/ptr_arith.rs b/src/test/ui/consts/miri_unleashed/ptr_arith.rs
new file mode 100644
index 000000000..13e6af36e
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/ptr_arith.rs
@@ -0,0 +1,22 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(core_intrinsics)]
+#![allow(const_err)]
+
+// During CTFE, we prevent pointer-to-int casts.
+// Pointer comparisons are prevented in the trait system.
+
+static PTR_INT_CAST: () = {
+ let x = &0 as *const _ as usize;
+ //~^ ERROR could not evaluate static initializer
+ //~| "exposing pointers" needs an rfc before being allowed inside constants
+ let _v = x == x;
+};
+
+static PTR_INT_TRANSMUTE: () = unsafe {
+ let x: usize = std::mem::transmute(&0);
+ let _v = x + 0;
+ //~^ ERROR could not evaluate static initializer
+ //~| unable to turn pointer into raw bytes
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/ptr_arith.stderr b/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
new file mode 100644
index 000000000..f67ac4802
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
@@ -0,0 +1,26 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/ptr_arith.rs:9:13
+ |
+LL | let x = &0 as *const _ as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^ "exposing pointers" needs an rfc before being allowed inside constants
+
+error[E0080]: could not evaluate static initializer
+ --> $DIR/ptr_arith.rs:17:14
+ |
+LL | let _v = x + 0;
+ | ^ unable to turn pointer into raw bytes
+ |
+ = help: this code performed an operation that depends on the underlying bytes representing a pointer
+ = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/ptr_arith.rs:9:13
+ |
+LL | let x = &0 as *const _ as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/raw_mutable_const.rs b/src/test/ui/consts/miri_unleashed/raw_mutable_const.rs
new file mode 100644
index 000000000..cabd754e0
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/raw_mutable_const.rs
@@ -0,0 +1,10 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+#![allow(const_err)]
+
+use std::cell::UnsafeCell;
+
+const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
+//~^ ERROR: untyped pointers are not allowed in constant
+
+fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr b/src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr
new file mode 100644
index 000000000..e145f6dd2
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr
@@ -0,0 +1,16 @@
+error: untyped pointers are not allowed in constant
+ --> $DIR/raw_mutable_const.rs:7:1
+ |
+LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/raw_mutable_const.rs:7:38
+ |
+LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
diff --git a/src/test/ui/consts/miri_unleashed/slice_eq.rs b/src/test/ui/consts/miri_unleashed/slice_eq.rs
new file mode 100644
index 000000000..fd843105d
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/slice_eq.rs
@@ -0,0 +1,17 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// run-pass
+
+#![feature(const_raw_ptr_comparison)]
+
+const EMPTY_SLICE: &[i32] = &[];
+const EMPTY_EQ: bool = EMPTY_SLICE.as_ptr().guaranteed_eq(&[] as *const _);
+const EMPTY_EQ2: bool = EMPTY_SLICE.as_ptr().guaranteed_ne(&[] as *const _);
+const EMPTY_NE: bool = EMPTY_SLICE.as_ptr().guaranteed_ne(&[1] as *const _);
+const EMPTY_NE2: bool = EMPTY_SLICE.as_ptr().guaranteed_eq(&[1] as *const _);
+
+fn main() {
+ assert!(!EMPTY_EQ);
+ assert!(!EMPTY_EQ2);
+ assert!(!EMPTY_NE);
+ assert!(!EMPTY_NE2);
+}
diff --git a/src/test/ui/consts/miri_unleashed/tls.rs b/src/test/ui/consts/miri_unleashed/tls.rs
new file mode 100644
index 000000000..7d4f8962a
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/tls.rs
@@ -0,0 +1,24 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(thread_local)]
+#![allow(const_err)]
+
+use std::thread;
+
+#[thread_local]
+static A: u8 = 0;
+
+// Make sure we catch accessing thread-local storage.
+static TEST_BAD: () = {
+ unsafe { let _val = A; }
+ //~^ ERROR could not evaluate static initializer
+ //~| NOTE cannot access thread local static
+};
+
+// Make sure we catch taking a reference to thread-local storage.
+static TEST_BAD_REF: () = {
+ unsafe { let _val = &A; }
+ //~^ ERROR could not evaluate static initializer
+ //~| NOTE cannot access thread local static
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/tls.stderr b/src/test/ui/consts/miri_unleashed/tls.stderr
new file mode 100644
index 000000000..a49e50a3e
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/tls.stderr
@@ -0,0 +1,28 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/tls.rs:12:25
+ |
+LL | unsafe { let _val = A; }
+ | ^ cannot access thread local static (DefId(0:6 ~ tls[78b0]::A))
+
+error[E0080]: could not evaluate static initializer
+ --> $DIR/tls.rs:19:26
+ |
+LL | unsafe { let _val = &A; }
+ | ^ cannot access thread local static (DefId(0:6 ~ tls[78b0]::A))
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/tls.rs:12:25
+ |
+LL | unsafe { let _val = A; }
+ | ^
+help: skipping check that does not even have a feature gate
+ --> $DIR/tls.rs:19:26
+ |
+LL | unsafe { let _val = &A; }
+ | ^
+
+error: aborting due to 2 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.