about summary refs log tree commit diff
path: root/tests/ui/pattern
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2024-01-06 13:13:18 +0800
committeryukang <moorekang@gmail.com>2024-04-25 04:54:25 +0800
commitbe9dbe910265da4f990d9adddb850cb2c72e63de (patch)
tree72c82795924bc13433ca27128c867c20d77c86d5 /tests/ui/pattern
parent7bb4f0889e8b133c5b03c46f31f2ae6432c00219 (diff)
downloadrust-be9dbe910265da4f990d9adddb850cb2c72e63de.tar.gz
rust-be9dbe910265da4f990d9adddb850cb2c72e63de.zip
Suggest ref mut for pattern matching assignment
Diffstat (limited to 'tests/ui/pattern')
-rw-r--r--tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr14
-rw-r--r--tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr28
-rw-r--r--tests/ui/pattern/mut-ref-mut-2021.stderr14
3 files changed, 40 insertions, 16 deletions
diff --git a/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr b/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr
index e25c30cd492..41d1b79d97d 100644
--- a/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr
+++ b/tests/ui/pattern/bindings-after-at/pat-at-same-name-both.stderr
@@ -70,13 +70,19 @@ error[E0384]: cannot assign twice to immutable variable `a`
   --> $DIR/pat-at-same-name-both.rs:13:15
    |
 LL |         Ok(a @ b @ a)
-   |                    -
-   |                    |
-   |                    first assignment to `a`
-   |                    help: consider making this binding mutable: `mut a`
+   |                    - first assignment to `a`
 LL |
 LL |         | Err(a @ b @ a)
    |               ^ cannot assign twice to immutable variable
+   |
+help: consider making this binding mutable
+   |
+LL |         Ok(a @ b @ mut a)
+   |                    ~~~~~
+help: to modify the original value, take a borrow instead
+   |
+LL |         Ok(a @ b @ ref mut a)
+   |                    ~~~~~~~~~
 
 error: aborting due to 12 previous errors
 
diff --git a/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr b/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr
index a033cc0655e..1e7b990b67c 100644
--- a/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr
+++ b/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr
@@ -15,12 +15,18 @@ error[E0384]: cannot assign twice to immutable variable `_x1`
   --> $DIR/borrowck-move-ref-pattern.rs:9:5
    |
 LL |     let [ref _x0_hold, _x1, ref xs_hold @ ..] = arr;
-   |                        ---
-   |                        |
-   |                        first assignment to `_x1`
-   |                        help: consider making this binding mutable: `mut _x1`
+   |                        --- first assignment to `_x1`
 LL |     _x1 = U;
    |     ^^^^^^^ cannot assign twice to immutable variable
+   |
+help: consider making this binding mutable
+   |
+LL |     let [ref _x0_hold, mut _x1, ref xs_hold @ ..] = arr;
+   |                        ~~~~~~~
+help: to modify the original value, take a borrow instead
+   |
+LL |     let [ref _x0_hold, ref mut _x1, ref xs_hold @ ..] = arr;
+   |                        ~~~~~~~~~~~
 
 error[E0505]: cannot move out of `arr[..]` because it is borrowed
   --> $DIR/borrowck-move-ref-pattern.rs:11:10
@@ -73,12 +79,18 @@ error[E0384]: cannot assign twice to immutable variable `_x1`
   --> $DIR/borrowck-move-ref-pattern.rs:23:5
    |
 LL |     let (ref _x0, _x1, ref _x2, ..) = tup;
-   |                   ---
-   |                   |
-   |                   first assignment to `_x1`
-   |                   help: consider making this binding mutable: `mut _x1`
+   |                   --- first assignment to `_x1`
 LL |     _x1 = U;
    |     ^^^^^^^ cannot assign twice to immutable variable
+   |
+help: consider making this binding mutable
+   |
+LL |     let (ref _x0, mut _x1, ref _x2, ..) = tup;
+   |                   ~~~~~~~
+help: to modify the original value, take a borrow instead
+   |
+LL |     let (ref _x0, ref mut _x1, ref _x2, ..) = tup;
+   |                   ~~~~~~~~~~~
 
 error[E0502]: cannot borrow `tup.0` as mutable because it is also borrowed as immutable
   --> $DIR/borrowck-move-ref-pattern.rs:24:20
diff --git a/tests/ui/pattern/mut-ref-mut-2021.stderr b/tests/ui/pattern/mut-ref-mut-2021.stderr
index eb31ffa0e30..ebf7979edb6 100644
--- a/tests/ui/pattern/mut-ref-mut-2021.stderr
+++ b/tests/ui/pattern/mut-ref-mut-2021.stderr
@@ -2,12 +2,18 @@ error[E0384]: cannot assign twice to immutable variable `a`
   --> $DIR/mut-ref-mut-2021.rs:9:5
    |
 LL |     let Foo(a) = Foo(0);
-   |             -
-   |             |
-   |             first assignment to `a`
-   |             help: consider making this binding mutable: `mut a`
+   |             - first assignment to `a`
 LL |     a = 42;
    |     ^^^^^^ cannot assign twice to immutable variable
+   |
+help: consider making this binding mutable
+   |
+LL |     let Foo(mut a) = Foo(0);
+   |             ~~~~~
+help: to modify the original value, take a borrow instead
+   |
+LL |     let Foo(ref mut a) = Foo(0);
+   |             ~~~~~~~~~
 
 error[E0384]: cannot assign twice to immutable variable `a`
   --> $DIR/mut-ref-mut-2021.rs:15:5