This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +16
-16
lines changed
compiler/rustc_mir/src/transform/check_consts Expand file tree Collapse file tree 10 files changed +16
-16
lines changed Original file line number Diff line number Diff line change @@ -242,8 +242,8 @@ impl NonConstOp for CellBorrow {
242242 ccx. tcx. sess,
243243 span,
244244 E0492 ,
245- "cannot borrow a constant which may contain \
246- interior mutability, create a static instead"
245+ "this borrow to an interior mutable value may end up in the final value of this {}" ,
246+ ccx . const_kind ( ) ,
247247 )
248248 }
249249}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use std::cell::Cell;
33const FOO : & ( Cell < usize > , bool ) = {
44 let mut a = ( Cell :: new ( 0 ) , false ) ;
55 a. 1 = true ; // sets `qualif(a)` to `qualif(a) | qualif(true)`
6- & { a} //~ ERROR cannot borrow a constant which may contain interior mutability
6+ & { a} //~ ERROR borrow to an interior mutable value may end up in the final value
77} ;
88
99fn main ( ) { }
Original file line number Diff line number Diff line change 1- error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
1+ error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
22 --> $DIR/partial_qualif.rs:6:5
33 |
44LL | &{a}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ use std::cell::Cell;
77const FOO : & Option < Cell < usize > > = {
88 let mut a = Some ( Cell :: new ( 0 ) ) ;
99 a = None ; // sets `qualif(a)` to `qualif(a) | qualif(None)`
10- & { a} //~ ERROR cannot borrow a constant which may contain interior mutability
10+ & { a} //~ ERROR borrow to an interior mutable value may end up in the final value
1111} ;
1212
1313fn main ( ) { }
Original file line number Diff line number Diff line change 1- error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
1+ error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
22 --> $DIR/qualif_overwrite.rs:10:5
33 |
44LL | &{a}
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use std::cell::Cell;
55const FOO : & Option < Cell < usize > > = {
66 let mut a = ( Some ( Cell :: new ( 0 ) ) , ) ;
77 a. 0 = None ; // sets `qualif(a)` to `qualif(a) | qualif(None)`
8- & { a. 0 } //~ ERROR cannot borrow a constant which may contain interior mutability
8+ & { a. 0 } //~ ERROR borrow to an interior mutable value may end up in the final value
99} ;
1010
1111fn main ( ) { }
Original file line number Diff line number Diff line change 1- error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
1+ error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
22 --> $DIR/qualif_overwrite_2.rs:8:5
33 |
44LL | &{a.0}
Original file line number Diff line number Diff line change 1- error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
1+ error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
22 --> $DIR/E0492.rs:4:33
33 |
44LL | const B: &'static AtomicUsize = &A;
55 | ^^
66
7- error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
7+ error[E0492]: this borrow to an interior mutable value may end up in the final value of this static
88 --> $DIR/E0492.rs:5:34
99 |
1010LL | static C: &'static AtomicUsize = &A;
Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ use std::cell::UnsafeCell;
22
33const A : UnsafeCell < usize > = UnsafeCell :: new ( 1 ) ;
44const B : & ' static UnsafeCell < usize > = & A ;
5- //~^ ERROR: may contain interior mutability
5+ //~^ ERROR: borrow to an interior mutable value
66
77struct C { a : UnsafeCell < usize > }
88const D : C = C { a : UnsafeCell :: new ( 1 ) } ;
99const E : & ' static UnsafeCell < usize > = & D . a ;
10- //~^ ERROR: may contain interior mutability
10+ //~^ ERROR: borrow to an interior mutable value
1111const F : & ' static C = & D ;
12- //~^ ERROR: may contain interior mutability
12+ //~^ ERROR: borrow to an interior mutable value
1313
1414fn main ( ) { }
Original file line number Diff line number Diff line change 1- error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
1+ error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
22 --> $DIR/issue-17718-const-borrow.rs:4:39
33 |
44LL | const B: &'static UnsafeCell<usize> = &A;
55 | ^^
66
7- error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
7+ error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
88 --> $DIR/issue-17718-const-borrow.rs:9:39
99 |
1010LL | const E: &'static UnsafeCell<usize> = &D.a;
1111 | ^^^^
1212
13- error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
13+ error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
1414 --> $DIR/issue-17718-const-borrow.rs:11:23
1515 |
1616LL | const F: &'static C = &D;
You can’t perform that action at this time.
0 commit comments