File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 1
1
// Ensure that we point the user to the erroneous borrow but not to any subsequent borrows of that
2
2
// initial one.
3
3
4
- const _X : i32 = {
4
+ const _ : i32 = {
5
5
let mut a = 5 ;
6
6
let p = & mut a; //~ ERROR references in constants may only refer to immutable values
7
7
@@ -11,4 +11,14 @@ const _X: i32 = {
11
11
* * * ppp
12
12
} ;
13
13
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
+
14
24
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -4,6 +4,13 @@ error[E0017]: references in constants may only refer to immutable values
4
4
LL | let p = &mut a;
5
5
| ^^^^^^ constants require immutable values
6
6
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
8
14
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`.
You can’t perform that action at this time.
0 commit comments