mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Also test shared borrows of Cell
for good errors
This commit is contained in:
parent
dd32d911d6
commit
d2bdaa8deb
@ -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() {}
|
||||
|
@ -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`.
|
||||
|
Loading…
Reference in New Issue
Block a user