summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/miri_unleashed
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/consts/miri_unleashed')
-rw-r--r--tests/ui/consts/miri_unleashed/abi-mismatch.rs18
-rw-r--r--tests/ui/consts/miri_unleashed/abi-mismatch.stderr28
-rw-r--r--tests/ui/consts/miri_unleashed/assoc_const.rs30
-rw-r--r--tests/ui/consts/miri_unleashed/assoc_const.stderr44
-rw-r--r--tests/ui/consts/miri_unleashed/assoc_const_2.rs28
-rw-r--r--tests/ui/consts/miri_unleashed/assoc_const_2.stderr27
-rw-r--r--tests/ui/consts/miri_unleashed/auxiliary/static_cross_crate.rs3
-rw-r--r--tests/ui/consts/miri_unleashed/box.rs12
-rw-r--r--tests/ui/consts/miri_unleashed/box.stderr32
-rw-r--r--tests/ui/consts/miri_unleashed/const_refers_to_static.32bit.stderr81
-rw-r--r--tests/ui/consts/miri_unleashed/const_refers_to_static.64bit.stderr81
-rw-r--r--tests/ui/consts/miri_unleashed/const_refers_to_static.rs33
-rw-r--r--tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr138
-rw-r--r--tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr138
-rw-r--r--tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs76
-rw-r--r--tests/ui/consts/miri_unleashed/drop.rs17
-rw-r--r--tests/ui/consts/miri_unleashed/drop.stderr24
-rw-r--r--tests/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs26
-rw-r--r--tests/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr11
-rw-r--r--tests/ui/consts/miri_unleashed/inline_asm.rs13
-rw-r--r--tests/ui/consts/miri_unleashed/inline_asm.stderr17
-rw-r--r--tests/ui/consts/miri_unleashed/mutable_references.rs36
-rw-r--r--tests/ui/consts/miri_unleashed/mutable_references.stderr37
-rw-r--r--tests/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr54
-rw-r--r--tests/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr54
-rw-r--r--tests/ui/consts/miri_unleashed/mutable_references_err.rs36
-rw-r--r--tests/ui/consts/miri_unleashed/mutating_global.rs15
-rw-r--r--tests/ui/consts/miri_unleashed/mutating_global.stderr9
-rw-r--r--tests/ui/consts/miri_unleashed/non_const_fn.rs11
-rw-r--r--tests/ui/consts/miri_unleashed/non_const_fn.stderr17
-rw-r--r--tests/ui/consts/miri_unleashed/ptr_arith.rs24
-rw-r--r--tests/ui/consts/miri_unleashed/ptr_arith.stderr26
-rw-r--r--tests/ui/consts/miri_unleashed/raw_mutable_const.rs8
-rw-r--r--tests/ui/consts/miri_unleashed/raw_mutable_const.stderr16
-rw-r--r--tests/ui/consts/miri_unleashed/slice_eq.rs13
-rw-r--r--tests/ui/consts/miri_unleashed/tls.rs23
-rw-r--r--tests/ui/consts/miri_unleashed/tls.stderr28
37 files changed, 1284 insertions, 0 deletions
diff --git a/tests/ui/consts/miri_unleashed/abi-mismatch.rs b/tests/ui/consts/miri_unleashed/abi-mismatch.rs
new file mode 100644
index 000000000..205f7183b
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/abi-mismatch.rs
@@ -0,0 +1,18 @@
+// Checks that we report ABI mismatches for "const extern fn"
+// compile-flags: -Z unleash-the-miri-inside-of-you
+
+#![feature(const_extern_fn)]
+
+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/tests/ui/consts/miri_unleashed/abi-mismatch.stderr b/tests/ui/consts/miri_unleashed/abi-mismatch.stderr
new file mode 100644
index 000000000..cf3fd88d0
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/abi-mismatch.stderr
@@ -0,0 +1,28 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/abi-mismatch.rs:9:5
+ |
+LL | my_fn();
+ | ^^^^^^^ calling a function with calling convention C using calling convention Rust
+ |
+note: inside `call_rust_fn`
+ --> $DIR/abi-mismatch.rs:9:5
+ |
+LL | my_fn();
+ | ^^^^^^^
+note: inside `VAL`
+ --> $DIR/abi-mismatch.rs:15:18
+ |
+LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/abi-mismatch.rs:9: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/tests/ui/consts/miri_unleashed/assoc_const.rs b/tests/ui/consts/miri_unleashed/assoc_const.rs
new file mode 100644
index 000000000..7bb0c1b77
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/assoc_const.rs
@@ -0,0 +1,30 @@
+// build-fail
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+// 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; //~ constant
+}
diff --git a/tests/ui/consts/miri_unleashed/assoc_const.stderr b/tests/ui/consts/miri_unleashed/assoc_const.stderr
new file mode 100644
index 000000000..e1da43c3a
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/assoc_const.stderr
@@ -0,0 +1,44 @@
+error[E0080]: evaluation of `<std::string::String as Bar<std::vec::Vec<u32>, std::string::String>>::F` failed
+ --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+ |
+ = note: calling non-const function `<Vec<u32> as Drop>::drop`
+ |
+note: inside `std::ptr::drop_in_place::<Vec<u32>> - shim(Some(Vec<u32>))`
+ --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+note: inside `std::ptr::drop_in_place::<(Vec<u32>, u32)> - shim(Some((Vec<u32>, u32)))`
+ --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+note: inside `<String as Bar<Vec<u32>, String>>::F`
+ --> $DIR/assoc_const.rs:12:31
+ |
+LL | const F: u32 = (U::X, 42).1;
+ | ^
+
+note: erroneous constant used
+ --> $DIR/assoc_const.rs:29:13
+ |
+LL | let y = <String as Bar<Vec<u32>, String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+note: erroneous constant used
+ --> $DIR/assoc_const.rs:29:13
+ |
+LL | let y = <String as Bar<Vec<u32>, String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+note: erroneous constant used
+ --> $DIR/assoc_const.rs:29:13
+ |
+LL | let y = <String as Bar<Vec<u32>, String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/assoc_const.rs:12: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`.
diff --git a/tests/ui/consts/miri_unleashed/assoc_const_2.rs b/tests/ui/consts/miri_unleashed/assoc_const_2.rs
new file mode 100644
index 000000000..aad5b3460
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/assoc_const_2.rs
@@ -0,0 +1,28 @@
+// build-fail
+
+// 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; //~ ERROR evaluation of `<std::string::String as Bar<std::string::String>>::F` failed
+}
+
+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; //~ constant
+}
diff --git a/tests/ui/consts/miri_unleashed/assoc_const_2.stderr b/tests/ui/consts/miri_unleashed/assoc_const_2.stderr
new file mode 100644
index 000000000..fc4b18056
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/assoc_const_2.stderr
@@ -0,0 +1,27 @@
+error[E0080]: evaluation of `<std::string::String as Bar<std::string::String>>::F` failed
+ --> $DIR/assoc_const_2.rs:10:20
+ |
+LL | const F: u32 = 100 / U::X;
+ | ^^^^^^^^^^ attempt to divide `100_u32` by zero
+
+note: erroneous constant used
+ --> $DIR/assoc_const_2.rs:27:13
+ |
+LL | let y = <String as Bar<String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+note: erroneous constant used
+ --> $DIR/assoc_const_2.rs:27:13
+ |
+LL | let y = <String as Bar<String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+note: erroneous constant used
+ --> $DIR/assoc_const_2.rs:27:13
+ |
+LL | let y = <String as Bar<String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/miri_unleashed/auxiliary/static_cross_crate.rs b/tests/ui/consts/miri_unleashed/auxiliary/static_cross_crate.rs
new file mode 100644
index 000000000..4fc6ae66a
--- /dev/null
+++ b/tests/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/tests/ui/consts/miri_unleashed/box.rs b/tests/ui/consts/miri_unleashed/box.rs
new file mode 100644
index 000000000..c2a260aa1
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/box.rs
@@ -0,0 +1,12 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(box_syntax)]
+
+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/tests/ui/consts/miri_unleashed/box.stderr b/tests/ui/consts/miri_unleashed/box.stderr
new file mode 100644
index 000000000..bc5d4a257
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/box.stderr
@@ -0,0 +1,32 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/box.rs:9: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:9:11
+ |
+LL | &mut *(box 0)
+ | ^^^^^^^
+help: skipping check for `const_mut_refs` feature
+ --> $DIR/box.rs:9:16
+ |
+LL | &mut *(box 0)
+ | ^
+help: skipping check for `const_mut_refs` feature
+ --> $DIR/box.rs:9:5
+ |
+LL | &mut *(box 0)
+ | ^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/box.rs:9: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/tests/ui/consts/miri_unleashed/const_refers_to_static.32bit.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static.32bit.stderr
new file mode 100644
index 000000000..a6f467b9e
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/const_refers_to_static.32bit.stderr
@@ -0,0 +1,81 @@
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:9:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `AtomicUsize::fetch_add`
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:14:14
+ |
+LL | unsafe { *(&FOO as *const _ as *const usize) }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:18:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^ constant accesses static
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static.rs:20:1
+ |
+LL | const REF_INTERIOR_MUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = 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) {
+ ╾─alloc4──╼ │ ╾──╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static.rs:27:1
+ |
+LL | const READ_IMMUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = 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) {
+ ╾─alloc5──╼ │ ╾──╼
+ }
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:9: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:9: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:14: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:18: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:18: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:23:18
+ |
+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:30:6
+ |
+LL | &FOO
+ | ^^^
+
+error: aborting due to 5 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static.64bit.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static.64bit.stderr
new file mode 100644
index 000000000..cfaf31a6e
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/const_refers_to_static.64bit.stderr
@@ -0,0 +1,81 @@
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:9:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `AtomicUsize::fetch_add`
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:14:14
+ |
+LL | unsafe { *(&FOO as *const _ as *const usize) }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:18:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^ constant accesses static
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static.rs:20:1
+ |
+LL | const REF_INTERIOR_MUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = 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) {
+ ╾───────alloc4────────╼ │ ╾──────╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static.rs:27:1
+ |
+LL | const READ_IMMUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = 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) {
+ ╾───────alloc5────────╼ │ ╾──────╼
+ }
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:9: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:9: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:14: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:18: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:18: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:23:18
+ |
+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:30:6
+ |
+LL | &FOO
+ | ^^^
+
+error: aborting due to 5 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static.rs b/tests/ui/consts/miri_unleashed/const_refers_to_static.rs
new file mode 100644
index 000000000..7ed5a48d9
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/const_refers_to_static.rs
@@ -0,0 +1,33 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// stderr-per-bitwidth
+
+use std::sync::atomic::AtomicUsize;
+use std::sync::atomic::Ordering;
+
+const MUTATE_INTERIOR_MUT: usize = {
+ static FOO: AtomicUsize = AtomicUsize::new(0);
+ FOO.fetch_add(1, Ordering::Relaxed) //~ERROR evaluation of constant value failed
+};
+
+const READ_INTERIOR_MUT: usize = {
+ static FOO: AtomicUsize = AtomicUsize::new(0);
+ unsafe { *(&FOO as *const _ as *const usize) } //~ERROR evaluation of constant value failed
+};
+
+static mut MUTABLE: u32 = 0;
+const READ_MUT: u32 = unsafe { MUTABLE }; //~ERROR evaluation of constant value failed
+
+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/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr
new file mode 100644
index 000000000..6df2fe3d0
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr
@@ -0,0 +1,138 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static_cross_crate.rs:10:1
+ |
+LL | const SLICE_MUT: &[u8; 1] = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = 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:34:9
+ |
+LL | SLICE_MUT => true,
+ | ^^^^^^^^^
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static_cross_crate.rs:15:1
+ |
+LL | const U8_MUT: &u8 = {
+ | ^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = 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:43:9
+ |
+LL | U8_MUT => true,
+ | ^^^^^^
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static_cross_crate.rs:22:15
+ |
+LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:54:9
+ |
+LL | U8_MUT2 => true,
+ | ^^^^^^^
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:62:9
+ |
+LL | U8_MUT3 => true,
+ | ^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:34:9
+ |
+LL | SLICE_MUT => true,
+ | ^^^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:43:9
+ |
+LL | U8_MUT => true,
+ | ^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:54:9
+ |
+LL | U8_MUT2 => true,
+ | ^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:62: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:12: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:12: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:17: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:17: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:17: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:22: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:27: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:27: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:27: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:27:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 12 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr
new file mode 100644
index 000000000..8802f3ada
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr
@@ -0,0 +1,138 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static_cross_crate.rs:10:1
+ |
+LL | const SLICE_MUT: &[u8; 1] = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = 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:34:9
+ |
+LL | SLICE_MUT => true,
+ | ^^^^^^^^^
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static_cross_crate.rs:15:1
+ |
+LL | const U8_MUT: &u8 = {
+ | ^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = 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:43:9
+ |
+LL | U8_MUT => true,
+ | ^^^^^^
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static_cross_crate.rs:22:15
+ |
+LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:54:9
+ |
+LL | U8_MUT2 => true,
+ | ^^^^^^^
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:62:9
+ |
+LL | U8_MUT3 => true,
+ | ^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:34:9
+ |
+LL | SLICE_MUT => true,
+ | ^^^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:43:9
+ |
+LL | U8_MUT => true,
+ | ^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:54:9
+ |
+LL | U8_MUT2 => true,
+ | ^^^^^^^
+
+error: could not evaluate constant pattern
+ --> $DIR/const_refers_to_static_cross_crate.rs:62: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:12: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:12: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:17: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:17: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:17: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:22: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:27: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:27: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:27: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:27:20
+ |
+LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 12 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
new file mode 100644
index 000000000..bf4f14f4d
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
@@ -0,0 +1,76 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// aux-build:static_cross_crate.rs
+// stderr-per-bitwidth
+#![feature(exclusive_range_pattern, half_open_range_patterns_in_slices)]
+
+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.
+const U8_MUT2: &u8 = {
+ unsafe { &(*static_cross_crate::ZERO_REF)[0] }
+ //~^ ERROR evaluation of constant value failed
+ //~| constant accesses static
+};
+const U8_MUT3: &u8 = {
+ unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
+ //~^ ERROR evaluation of constant value failed
+ //~| constant accesses static
+};
+
+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/tests/ui/consts/miri_unleashed/drop.rs b/tests/ui/consts/miri_unleashed/drop.rs
new file mode 100644
index 000000000..3942e7ef7
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/drop.rs
@@ -0,0 +1,17 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// error-pattern: calling non-const function `<Vec<i32> as Drop>::drop`
+
+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/tests/ui/consts/miri_unleashed/drop.stderr b/tests/ui/consts/miri_unleashed/drop.stderr
new file mode 100644
index 000000000..4f60b8820
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/drop.stderr
@@ -0,0 +1,24 @@
+error[E0080]: could not evaluate static initializer
+ --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+ |
+ = note: calling non-const function `<Vec<i32> as Drop>::drop`
+ |
+note: inside `std::ptr::drop_in_place::<Vec<i32>> - shim(Some(Vec<i32>))`
+ --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+note: inside `TEST_BAD`
+ --> $DIR/drop.rs:17:1
+ |
+LL | };
+ | ^
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/drop.rs:16: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/tests/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs b/tests/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs
new file mode 100644
index 000000000..c24d3338e
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs
@@ -0,0 +1,26 @@
+// 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 destructor of
+}
+
+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/tests/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr b/tests/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr
new file mode 100644
index 000000000..45ed88b1b
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr
@@ -0,0 +1,11 @@
+error[E0493]: destructor of `(T, u32)` cannot be evaluated at compile-time
+ --> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:9:20
+ |
+LL | const F: u32 = (U::X, 42).1;
+ | ^^^^^^^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constants
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0493`.
diff --git a/tests/ui/consts/miri_unleashed/inline_asm.rs b/tests/ui/consts/miri_unleashed/inline_asm.rs
new file mode 100644
index 000000000..6fd52ceb2
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/inline_asm.rs
@@ -0,0 +1,13 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// only-x86_64
+
+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/tests/ui/consts/miri_unleashed/inline_asm.stderr b/tests/ui/consts/miri_unleashed/inline_asm.stderr
new file mode 100644
index 000000000..6317cd882
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/inline_asm.stderr
@@ -0,0 +1,17 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/inline_asm.rs:10: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:10: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/tests/ui/consts/miri_unleashed/mutable_references.rs b/tests/ui/consts/miri_unleashed/mutable_references.rs
new file mode 100644
index 000000000..4e9964647
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/mutable_references.rs
@@ -0,0 +1,36 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+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/tests/ui/consts/miri_unleashed/mutable_references.stderr b/tests/ui/consts/miri_unleashed/mutable_references.stderr
new file mode 100644
index 000000000..3ed96701a
--- /dev/null
+++ b/tests/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:35: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:8:26
+ |
+LL | static FOO: &&mut u32 = &&mut 42;
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:12:23
+ |
+LL | static BAR: &mut () = &mut ();
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:17:28
+ |
+LL | static BOO: &mut Foo<()> = &mut Foo(());
+ | ^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:25:8
+ |
+LL | x: &UnsafeCell::new(42),
+ | ^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references.rs:29: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/tests/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr b/tests/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr
new file mode 100644
index 000000000..0ea179240
--- /dev/null
+++ b/tests/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:15: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:25: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:29: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:16:8
+ |
+LL | x: &UnsafeCell::new(42),
+ | ^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references_err.rs:25: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:29: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/tests/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr b/tests/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr
new file mode 100644
index 000000000..67959d256
--- /dev/null
+++ b/tests/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:15: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:25: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:29: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:16:8
+ |
+LL | x: &UnsafeCell::new(42),
+ | ^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/mutable_references_err.rs:25: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:29: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/tests/ui/consts/miri_unleashed/mutable_references_err.rs b/tests/ui/consts/miri_unleashed/mutable_references_err.rs
new file mode 100644
index 000000000..6399b122b
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/mutable_references_err.rs
@@ -0,0 +1,36 @@
+// stderr-per-bitwidth
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+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/tests/ui/consts/miri_unleashed/mutating_global.rs b/tests/ui/consts/miri_unleashed/mutating_global.rs
new file mode 100644
index 000000000..231f4af0a
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/mutating_global.rs
@@ -0,0 +1,15 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+// 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/tests/ui/consts/miri_unleashed/mutating_global.stderr b/tests/ui/consts/miri_unleashed/mutating_global.stderr
new file mode 100644
index 000000000..c8770c8d7
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/mutating_global.stderr
@@ -0,0 +1,9 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/mutating_global.rs:9: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/tests/ui/consts/miri_unleashed/non_const_fn.rs b/tests/ui/consts/miri_unleashed/non_const_fn.rs
new file mode 100644
index 000000000..44ab60dca
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/non_const_fn.rs
@@ -0,0 +1,11 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+// 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/tests/ui/consts/miri_unleashed/non_const_fn.stderr b/tests/ui/consts/miri_unleashed/non_const_fn.stderr
new file mode 100644
index 000000000..57836f796
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/non_const_fn.stderr
@@ -0,0 +1,17 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/non_const_fn.rs:7: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:7: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/tests/ui/consts/miri_unleashed/ptr_arith.rs b/tests/ui/consts/miri_unleashed/ptr_arith.rs
new file mode 100644
index 000000000..4d12960b8
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/ptr_arith.rs
@@ -0,0 +1,24 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(core_intrinsics)]
+
+// 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
+ 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
+};
+
+// I'd love to test pointer comparison, but that is not possible since
+// their `PartialEq` impl is non-`const`.
+
+fn main() {}
diff --git a/tests/ui/consts/miri_unleashed/ptr_arith.stderr b/tests/ui/consts/miri_unleashed/ptr_arith.stderr
new file mode 100644
index 000000000..30fd3a55e
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/ptr_arith.stderr
@@ -0,0 +1,26 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/ptr_arith.rs:8:13
+ |
+LL | let x = &0 as *const _ as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^ exposing pointers is not possible at compile-time
+
+error[E0080]: could not evaluate static initializer
+ --> $DIR/ptr_arith.rs:16: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:8: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/tests/ui/consts/miri_unleashed/raw_mutable_const.rs b/tests/ui/consts/miri_unleashed/raw_mutable_const.rs
new file mode 100644
index 000000000..5f8ec4e6e
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/raw_mutable_const.rs
@@ -0,0 +1,8 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+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/tests/ui/consts/miri_unleashed/raw_mutable_const.stderr b/tests/ui/consts/miri_unleashed/raw_mutable_const.stderr
new file mode 100644
index 000000000..f8dc11d69
--- /dev/null
+++ b/tests/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:5: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:5: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/tests/ui/consts/miri_unleashed/slice_eq.rs b/tests/ui/consts/miri_unleashed/slice_eq.rs
new file mode 100644
index 000000000..83e10bf12
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/slice_eq.rs
@@ -0,0 +1,13 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+// run-pass
+
+#![feature(const_raw_ptr_comparison)]
+
+const EMPTY_SLICE: &[i32] = &[];
+const EMPTY_EQ: Option<bool> = EMPTY_SLICE.as_ptr().guaranteed_eq(&[] as *const _);
+const EMPTY_EQ2: Option<bool> = EMPTY_SLICE.as_ptr().guaranteed_eq(&[1] as *const _);
+
+fn main() {
+ assert!(EMPTY_EQ.is_none());
+ assert!(EMPTY_EQ2.is_none());
+}
diff --git a/tests/ui/consts/miri_unleashed/tls.rs b/tests/ui/consts/miri_unleashed/tls.rs
new file mode 100644
index 000000000..d06d7cf19
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/tls.rs
@@ -0,0 +1,23 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(thread_local)]
+
+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/tests/ui/consts/miri_unleashed/tls.stderr b/tests/ui/consts/miri_unleashed/tls.stderr
new file mode 100644
index 000000000..7aaeadd04
--- /dev/null
+++ b/tests/ui/consts/miri_unleashed/tls.stderr
@@ -0,0 +1,28 @@
+error[E0080]: could not evaluate static initializer
+ --> $DIR/tls.rs:11:25
+ |
+LL | unsafe { let _val = A; }
+ | ^ cannot access thread local static (DefId(0:4 ~ tls[78b0]::A))
+
+error[E0080]: could not evaluate static initializer
+ --> $DIR/tls.rs:18:26
+ |
+LL | unsafe { let _val = &A; }
+ | ^ cannot access thread local static (DefId(0:4 ~ tls[78b0]::A))
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/tls.rs:11:25
+ |
+LL | unsafe { let _val = A; }
+ | ^
+help: skipping check that does not even have a feature gate
+ --> $DIR/tls.rs:18: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`.