about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/ui/consts/const-multi-ref.rs12
-rw-r--r--src/test/ui/consts/const-multi-ref.stderr11
2 files changed, 20 insertions, 3 deletions
diff --git a/src/test/ui/consts/const-multi-ref.rs b/src/test/ui/consts/const-multi-ref.rs
index 45269042328..5e2be0d4f3f 100644
--- a/src/test/ui/consts/const-multi-ref.rs
+++ b/src/test/ui/consts/const-multi-ref.rs
@@ -1,7 +1,7 @@
 // Ensure that we point the user to the erroneous borrow but not to any subsequent borrows of that
 // initial one.
 
-const _X: i32 = {
+const _: i32 = {
     let mut a = 5;
     let p = &mut a; //~ ERROR references in constants may only refer to immutable values
 
@@ -11,4 +11,14 @@ const _X: i32 = {
     ***ppp
 };
 
+const _: std::cell::Cell<i32> = {
+    let mut a = std::cell::Cell::new(5);
+    let p = &a; //~ ERROR cannot borrow a constant which may contain interior mutability
+
+    let reborrow = {p};
+    let pp = &reborrow;
+    let ppp = &pp;
+    a
+};
+
 fn main() {}
diff --git a/src/test/ui/consts/const-multi-ref.stderr b/src/test/ui/consts/const-multi-ref.stderr
index 50533b0b1cc..ed3837e9c9e 100644
--- a/src/test/ui/consts/const-multi-ref.stderr
+++ b/src/test/ui/consts/const-multi-ref.stderr
@@ -4,6 +4,13 @@ error[E0017]: references in constants may only refer to immutable values
 LL |     let p = &mut a;
    |             ^^^^^^ constants require immutable values
 
-error: aborting due to previous error
+error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
+  --> $DIR/const-multi-ref.rs:16:13
+   |
+LL |     let p = &a;
+   |             ^^
+
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0017`.
+Some errors have detailed explanations: E0017, E0492.
+For more information about an error, try `rustc --explain E0017`.