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 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+
1424fn 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
44LL | 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`.
You can’t perform that action at this time.
0 commit comments