From a137ff17069feb67a2ef5a0f3ddbe09707c2d6cd Mon Sep 17 00:00:00 2001 From: oli Date: Sun, 3 Jan 2021 13:45:16 +0000 Subject: [PATCH] Update now-more-precise operation with a preciser message --- compiler/rustc_mir/src/transform/check_consts/ops.rs | 4 ++-- src/test/ui/consts/partial_qualif.rs | 2 +- src/test/ui/consts/partial_qualif.stderr | 2 +- src/test/ui/consts/qualif_overwrite.rs | 2 +- src/test/ui/consts/qualif_overwrite.stderr | 2 +- src/test/ui/consts/qualif_overwrite_2.rs | 2 +- src/test/ui/consts/qualif_overwrite_2.stderr | 2 +- src/test/ui/error-codes/E0492.stderr | 4 ++-- src/test/ui/issues/issue-17718-const-borrow.rs | 6 +++--- src/test/ui/issues/issue-17718-const-borrow.stderr | 6 +++--- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index a85303d4cd3..cf81b69fede 100644 --- a/compiler/rustc_mir/src/transform/check_consts/ops.rs +++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs @@ -242,8 +242,8 @@ fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder< 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(), ) } } diff --git a/src/test/ui/consts/partial_qualif.rs b/src/test/ui/consts/partial_qualif.rs index 32c68e69f4b..4aacdec7c51 100644 --- a/src/test/ui/consts/partial_qualif.rs +++ b/src/test/ui/consts/partial_qualif.rs @@ -3,7 +3,7 @@ const FOO: &(Cell, 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() {} diff --git a/src/test/ui/consts/partial_qualif.stderr b/src/test/ui/consts/partial_qualif.stderr index 221e449b6f9..5ea0cbc4f7c 100644 --- a/src/test/ui/consts/partial_qualif.stderr +++ b/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} diff --git a/src/test/ui/consts/qualif_overwrite.rs b/src/test/ui/consts/qualif_overwrite.rs index 9b3f6786ae6..485a4a2fcc3 100644 --- a/src/test/ui/consts/qualif_overwrite.rs +++ b/src/test/ui/consts/qualif_overwrite.rs @@ -7,7 +7,7 @@ const FOO: &Option> = { 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() {} diff --git a/src/test/ui/consts/qualif_overwrite.stderr b/src/test/ui/consts/qualif_overwrite.stderr index fbaae711d7c..995f8600587 100644 --- a/src/test/ui/consts/qualif_overwrite.stderr +++ b/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} diff --git a/src/test/ui/consts/qualif_overwrite_2.rs b/src/test/ui/consts/qualif_overwrite_2.rs index fa79b5c14a7..6b90988869d 100644 --- a/src/test/ui/consts/qualif_overwrite_2.rs +++ b/src/test/ui/consts/qualif_overwrite_2.rs @@ -5,7 +5,7 @@ const FOO: &Option> = { 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() {} diff --git a/src/test/ui/consts/qualif_overwrite_2.stderr b/src/test/ui/consts/qualif_overwrite_2.stderr index a393c4e336d..006199514fc 100644 --- a/src/test/ui/consts/qualif_overwrite_2.stderr +++ b/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} diff --git a/src/test/ui/error-codes/E0492.stderr b/src/test/ui/error-codes/E0492.stderr index 54306433b87..9aa84c2bff3 100644 --- a/src/test/ui/error-codes/E0492.stderr +++ b/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; diff --git a/src/test/ui/issues/issue-17718-const-borrow.rs b/src/test/ui/issues/issue-17718-const-borrow.rs index b11e83144ed..4b13c0f0c15 100644 --- a/src/test/ui/issues/issue-17718-const-borrow.rs +++ b/src/test/ui/issues/issue-17718-const-borrow.rs @@ -2,13 +2,13 @@ const A: UnsafeCell = UnsafeCell::new(1); const B: &'static UnsafeCell = &A; -//~^ ERROR: may contain interior mutability +//~^ ERROR: borrow to an interior mutable value struct C { a: UnsafeCell } const D: C = C { a: UnsafeCell::new(1) }; const E: &'static UnsafeCell = &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() {} diff --git a/src/test/ui/issues/issue-17718-const-borrow.stderr b/src/test/ui/issues/issue-17718-const-borrow.stderr index b4330049689..c94ae2a3a18 100644 --- a/src/test/ui/issues/issue-17718-const-borrow.stderr +++ b/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 = &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 = &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;