Skip to content

Commit

Permalink
Update now-more-precise operation with a preciser message
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 3, 2021
1 parent e5330a4 commit a137ff1
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/transform/check_consts/ops.rs
Expand Up @@ -242,8 +242,8 @@ impl NonConstOp for CellBorrow {
ccx.tcx.sess,
span,
E0492,
"cannot borrow a constant which may contain \
interior mutability, create a static instead"
"this borrow to an interior mutable value may end up in the final value of this {}",
ccx.const_kind(),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/partial_qualif.rs
Expand Up @@ -3,7 +3,7 @@ use std::cell::Cell;
const FOO: &(Cell<usize>, bool) = {
let mut a = (Cell::new(0), false);
a.1 = true; // sets `qualif(a)` to `qualif(a) | qualif(true)`
&{a} //~ ERROR cannot borrow a constant which may contain interior mutability
&{a} //~ ERROR borrow to an interior mutable value may end up in the final value
};

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/consts/partial_qualif.stderr
@@ -1,4 +1,4 @@
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
--> $DIR/partial_qualif.rs:6:5
|
LL | &{a}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/qualif_overwrite.rs
Expand Up @@ -7,7 +7,7 @@ use std::cell::Cell;
const FOO: &Option<Cell<usize>> = {
let mut a = Some(Cell::new(0));
a = None; // sets `qualif(a)` to `qualif(a) | qualif(None)`
&{a}//~ ERROR cannot borrow a constant which may contain interior mutability
&{a} //~ ERROR borrow to an interior mutable value may end up in the final value
};

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/consts/qualif_overwrite.stderr
@@ -1,4 +1,4 @@
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
--> $DIR/qualif_overwrite.rs:10:5
|
LL | &{a}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/qualif_overwrite_2.rs
Expand Up @@ -5,7 +5,7 @@ use std::cell::Cell;
const FOO: &Option<Cell<usize>> = {
let mut a = (Some(Cell::new(0)),);
a.0 = None; // sets `qualif(a)` to `qualif(a) | qualif(None)`
&{a.0} //~ ERROR cannot borrow a constant which may contain interior mutability
&{a.0} //~ ERROR borrow to an interior mutable value may end up in the final value
};

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/consts/qualif_overwrite_2.stderr
@@ -1,4 +1,4 @@
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
--> $DIR/qualif_overwrite_2.rs:8:5
|
LL | &{a.0}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0492.stderr
@@ -1,10 +1,10 @@
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
--> $DIR/E0492.rs:4:33
|
LL | const B: &'static AtomicUsize = &A;
| ^^

error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
error[E0492]: this borrow to an interior mutable value may end up in the final value of this static
--> $DIR/E0492.rs:5:34
|
LL | static C: &'static AtomicUsize = &A;
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/issues/issue-17718-const-borrow.rs
Expand Up @@ -2,13 +2,13 @@ use std::cell::UnsafeCell;

const A: UnsafeCell<usize> = UnsafeCell::new(1);
const B: &'static UnsafeCell<usize> = &A;
//~^ ERROR: may contain interior mutability
//~^ ERROR: borrow to an interior mutable value

struct C { a: UnsafeCell<usize> }
const D: C = C { a: UnsafeCell::new(1) };
const E: &'static UnsafeCell<usize> = &D.a;
//~^ ERROR: may contain interior mutability
//~^ ERROR: borrow to an interior mutable value
const F: &'static C = &D;
//~^ ERROR: may contain interior mutability
//~^ ERROR: borrow to an interior mutable value

fn main() {}
6 changes: 3 additions & 3 deletions src/test/ui/issues/issue-17718-const-borrow.stderr
@@ -1,16 +1,16 @@
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
--> $DIR/issue-17718-const-borrow.rs:4:39
|
LL | const B: &'static UnsafeCell<usize> = &A;
| ^^

error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
--> $DIR/issue-17718-const-borrow.rs:9:39
|
LL | const E: &'static UnsafeCell<usize> = &D.a;
| ^^^^

error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
error[E0492]: this borrow to an interior mutable value may end up in the final value of this constant
--> $DIR/issue-17718-const-borrow.rs:11:23
|
LL | const F: &'static C = &D;
Expand Down

0 comments on commit a137ff1

Please sign in to comment.