]> git.lizzy.rs Git - rust.git/commitdiff
Also test shared borrows of `Cell` for good errors
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Tue, 26 Nov 2019 20:10:44 +0000 (12:10 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Wed, 27 Nov 2019 22:37:06 +0000 (14:37 -0800)
src/test/ui/consts/const-multi-ref.rs
src/test/ui/consts/const-multi-ref.stderr

index 4526904232875ec2a6e3c9941659c09a1b80d3a8..5e2be0d4f3f02ee73be0731b934390bdbc4de1d2 100644 (file)
@@ -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
 
     ***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() {}
index 50533b0b1cceefa2250022570ad0d11ef8d554f8..ed3837e9c9ee589be2aea3a8298887e2ac8dfb93 100644 (file)
@@ -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`.