Also test shared borrows of Cell for good errors

This commit is contained in:
Dylan MacKenzie 2019-11-26 12:10:44 -08:00
parent dd32d911d6
commit d2bdaa8deb
2 changed files with 20 additions and 3 deletions

View 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
@ -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() {}

View 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;
| ^^
For more information about this error, try `rustc --explain E0017`.
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0017, E0492.
For more information about an error, try `rustc --explain E0017`.