about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_const.rs3
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_const.stderr23
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references.rs5
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references.stderr4
-rw-r--r--src/test/ui/consts/miri_unleashed/read_from_static.rs11
5 files changed, 37 insertions, 9 deletions
diff --git a/src/test/ui/consts/miri_unleashed/mutable_const.rs b/src/test/ui/consts/miri_unleashed/mutable_const.rs
index cf5e6d60025..972f59549ea 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_const.rs
+++ b/src/test/ui/consts/miri_unleashed/mutable_const.rs
@@ -1,6 +1,7 @@
 // compile-flags: -Zunleash-the-miri-inside-of-you
 
 #![feature(const_raw_ptr_deref)]
+#![feature(const_mut_refs)]
 #![deny(const_err)]
 
 use std::cell::UnsafeCell;
@@ -12,7 +13,7 @@ const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
 const MUTATING_BEHIND_RAW: () = {
     // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
     unsafe {
-        *MUTABLE_BEHIND_RAW = 99 //~ ERROR constant contains unimplemented expression type
+        *MUTABLE_BEHIND_RAW = 99 //~ ERROR any use of this value will cause an error
     }
 };
 
diff --git a/src/test/ui/consts/miri_unleashed/mutable_const.stderr b/src/test/ui/consts/miri_unleashed/mutable_const.stderr
index 1a18063625b..9daca765c7c 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_const.stderr
+++ b/src/test/ui/consts/miri_unleashed/mutable_const.stderr
@@ -1,15 +1,26 @@
 warning: skipping const checks
-  --> $DIR/mutable_const.rs:9:38
+  --> $DIR/mutable_const.rs:10:38
    |
 LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
    |                                      ^^^^^^^^^^^^^^^^^^^^
 
-error[E0019]: constant contains unimplemented expression type
-  --> $DIR/mutable_const.rs:15:9
+error: any use of this value will cause an error
+  --> $DIR/mutable_const.rs:16:9
    |
-LL |         *MUTABLE_BEHIND_RAW = 99
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^
+LL | / const MUTATING_BEHIND_RAW: () = {
+LL | |     // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
+LL | |     unsafe {
+LL | |         *MUTABLE_BEHIND_RAW = 99
+   | |         ^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify constant memory
+LL | |     }
+LL | | };
+   | |__-
+   |
+note: lint level defined here
+  --> $DIR/mutable_const.rs:5:9
+   |
+LL | #![deny(const_err)]
+   |         ^^^^^^^^^
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0019`.
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references.rs b/src/test/ui/consts/miri_unleashed/mutable_references.rs
index d95833e3071..fe3c4ee70f2 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_references.rs
+++ b/src/test/ui/consts/miri_unleashed/mutable_references.rs
@@ -6,12 +6,16 @@ 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(());
 
 struct Meh {
@@ -25,6 +29,7 @@ static MEH: Meh = Meh {
     //~^ WARN: skipping const checks
 };
 
+// this is fine for the same reason as `BAR`.
 static OH_YES: &mut i32 = &mut 42;
 
 fn main() {
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references.stderr b/src/test/ui/consts/miri_unleashed/mutable_references.stderr
index ce1f5f38dd9..3e1300c63c1 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_references.stderr
+++ b/src/test/ui/consts/miri_unleashed/mutable_references.stderr
@@ -1,11 +1,11 @@
 warning: skipping const checks
-  --> $DIR/mutable_references.rs:24:8
+  --> $DIR/mutable_references.rs:28:8
    |
 LL |     x: &UnsafeCell::new(42),
    |        ^^^^^^^^^^^^^^^^^^^^
 
 error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
-  --> $DIR/mutable_references.rs:34:5
+  --> $DIR/mutable_references.rs:39:5
    |
 LL |     *OH_YES = 99;
    |     ^^^^^^^^^^^^ cannot assign
diff --git a/src/test/ui/consts/miri_unleashed/read_from_static.rs b/src/test/ui/consts/miri_unleashed/read_from_static.rs
new file mode 100644
index 00000000000..821c501c9fc
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/read_from_static.rs
@@ -0,0 +1,11 @@
+// run-pass
+// compile-flags: -Zunleash-the-miri-inside-of-you
+#![feature(const_mut_refs)]
+#![allow(const_err)]
+
+static OH_YES: &mut i32 = &mut 42;
+
+fn main() {
+    // Make sure `OH_YES` can be read.
+    assert_eq!(*OH_YES, 42);
+}