Skip to content

Commit d2bdaa8

Browse files
Also test shared borrows of Cell for good errors
1 parent dd32d91 commit d2bdaa8

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/test/ui/consts/const-multi-ref.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Ensure that we point the user to the erroneous borrow but not to any subsequent borrows of that
22
// initial one.
33

4-
const _X: i32 = {
4+
const _: i32 = {
55
let mut a = 5;
66
let p = &mut a; //~ ERROR references in constants may only refer to immutable values
77

@@ -11,4 +11,14 @@ const _X: i32 = {
1111
***ppp
1212
};
1313

14+
const _: std::cell::Cell<i32> = {
15+
let mut a = std::cell::Cell::new(5);
16+
let p = &a; //~ ERROR cannot borrow a constant which may contain interior mutability
17+
18+
let reborrow = {p};
19+
let pp = &reborrow;
20+
let ppp = &pp;
21+
a
22+
};
23+
1424
fn main() {}

src/test/ui/consts/const-multi-ref.stderr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ error[E0017]: references in constants may only refer to immutable values
44
LL | let p = &mut a;
55
| ^^^^^^ constants require immutable values
66

7-
error: aborting due to previous error
7+
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
8+
--> $DIR/const-multi-ref.rs:16:13
9+
|
10+
LL | let p = &a;
11+
| ^^
12+
13+
error: aborting due to 2 previous errors
814

9-
For more information about this error, try `rustc --explain E0017`.
15+
Some errors have detailed explanations: E0017, E0492.
16+
For more information about an error, try `rustc --explain E0017`.

0 commit comments

Comments
 (0)