about summary refs log tree commit diff
path: root/src/test/ui/pattern
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-12 01:00:43 +0000
committerbors <bors@rust-lang.org>2021-07-12 01:00:43 +0000
commite97c29bda238cf55ddd7eec772deb823364b1846 (patch)
tree28e24188a597bb5d699e9e135d09868c0d1b6788 /src/test/ui/pattern
parent54aaca862374a8f296402822ec47d4f1586d54e3 (diff)
parent5eb83f4ec3761b69e839f364e127b8c307f6e196 (diff)
downloadrust-e97c29bda238cf55ddd7eec772deb823364b1846.tar.gz
rust-e97c29bda238cf55ddd7eec772deb823364b1846.zip
Auto merge of #86815 - FabianWolff:issue-84210, r=varkor
Improve error reporting for modifications behind `&` references

I had a look at #84210 and noticed that #85823 has effectively already fixed #84210.

However, the string matching in #85823 is _very_ crude and already breaks down when a variable name starts with `mut`. I have made this a bit more robust; further improvements could definitely be made but are complicated by the lack of information provided by an earlier pass:
https://github.com/rust-lang/rust/blob/ce331ee6ee010438d1a58c7da8ced4f26d69a20e/compiler/rustc_mir_build/src/build/matches/mod.rs#L2103-L2107

I have also fixed a missing comma in the error message.
Diffstat (limited to 'src/test/ui/pattern')
-rw-r--r--src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.rs4
-rw-r--r--src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.rs b/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.rs
index 9c320edc4dc..a6144c9497d 100644
--- a/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.rs
+++ b/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.rs
@@ -23,8 +23,8 @@ fn tuple() {
     _x1 = U; //~ ERROR cannot assign twice to immutable variable
     let _x0_hold = &mut tup.0; //~ ERROR cannot borrow `tup.0` as mutable because it is also
     let (ref mut _x0_hold, ..) = tup; //~ ERROR cannot borrow `tup.0` as mutable because it is also
-    *_x0 = U; //~ ERROR cannot assign to `*_x0` which is behind a `&` reference
-    *_x2 = U; //~ ERROR cannot assign to `*_x2` which is behind a `&` reference
+    *_x0 = U; //~ ERROR cannot assign to `*_x0`, which is behind a `&` reference
+    *_x2 = U; //~ ERROR cannot assign to `*_x2`, which is behind a `&` reference
     drop(tup.1); //~ ERROR use of moved value: `tup.1`
     let _x1_hold = &tup.1; //~ ERROR borrow of moved value: `tup.1`
     let (.., ref mut _x3) = tup;
diff --git a/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr b/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr
index d0726f05cc3..5beca04d285 100644
--- a/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr
+++ b/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr
@@ -101,7 +101,7 @@ LL |     let (ref mut _x0_hold, ..) = tup;
 LL |     *_x0 = U;
    |     -------- immutable borrow later used here
 
-error[E0594]: cannot assign to `*_x0` which is behind a `&` reference
+error[E0594]: cannot assign to `*_x0`, which is behind a `&` reference
   --> $DIR/borrowck-move-ref-pattern.rs:26:5
    |
 LL |     let (ref _x0, _x1, ref _x2, ..) = tup;
@@ -110,7 +110,7 @@ LL |     let (ref _x0, _x1, ref _x2, ..) = tup;
 LL |     *_x0 = U;
    |     ^^^^^^^^ `_x0` is a `&` reference, so the data it refers to cannot be written
 
-error[E0594]: cannot assign to `*_x2` which is behind a `&` reference
+error[E0594]: cannot assign to `*_x2`, which is behind a `&` reference
   --> $DIR/borrowck-move-ref-pattern.rs:27:5
    |
 LL |     let (ref _x0, _x1, ref _x2, ..) = tup;