rust/tests/ui/pattern/move-ref-patterns/move-ref-patterns-closure-captures-inside.stderr
Esteban Küber 11061831f7 Mention type that could be Clone but isn't in more cases
When encountering a moved value of a type that isn't `Clone` because of unmet obligations, but where all the unmet predicates reference crate-local types, mention them and suggest cloning, as we do in other cases already:

```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
  --> f111.rs:14:25
   |
13 | fn do_stuff(foo: Option<Foo>) {
   |             --- captured outer variable
14 |     require_fn_trait(|| async {
   |                      -- ^^^^^ `foo` is moved here
   |                      |
   |                      captured by this `Fn` closure
15 |         if foo.map_or(false, |f| f.foo()) {
   |            ---
   |            |
   |            variable moved due to use in coroutine
   |            move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
   |
note: if `Foo` implemented `Clone`, you could clone the value
  --> f111.rs:4:1
   |
4  | struct Foo;
   | ^^^^^^^^^^ consider implementing `Clone` for this type
...
15 |         if foo.map_or(false, |f| f.foo()) {
   |            --- you could clone this value
```
2025-07-25 18:34:10 +00:00

486 lines
19 KiB
Plaintext

error[E0382]: borrow of moved value: `tup0`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:31:10
|
LL | let mut tup0 = (S, S);
| -------- move occurs because `tup0` has type `(S, S)`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
LL | // Tuples...
LL | let (ref mut borrow, mov) = tup0;
| ---- variable moved due to use in closure
...
LL | drop(&tup0);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup1`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:32:10
|
LL | let mut tup1 = (S, S, S);
| -------- move occurs because `tup1` has type `(S, S, S)`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | let (mov, _, ref mut borrow) = tup1;
| ---- variable moved due to use in closure
...
LL | drop(&tup1);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup2`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:33:10
|
LL | let tup2 = (S, S);
| ---- move occurs because `tup2` has type `(S, S)`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | let (ref borrow, mov) = tup2;
| ---- variable moved due to use in closure
...
LL | drop(&tup2);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup3`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:34:10
|
LL | let tup3 = (S, S, S);
| ---- move occurs because `tup3` has type `(S, S, S)`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | let (mov, _, ref borrow) = tup3;
| ---- variable moved due to use in closure
...
LL | drop(&tup3);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup4`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:39:10
|
LL | let tup4 = (S, S);
| ---- move occurs because `tup4` has type `(S, S)`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | let (ref borrow, mov) = tup4;
| ---- variable moved due to use in closure
...
LL | drop(&tup4.0);
| ^^^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `arr0`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:41:10
|
LL | let mut arr0 = [S, S, S];
| -------- move occurs because `arr0` has type `[S; 3]`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | let [mov @ .., ref borrow] = arr0;
| ---- variable moved due to use in closure
...
LL | drop(&arr0);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `arr1`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:42:36
|
LL | let mut arr1 = [S, S, S, S, S];
| -------- move occurs because `arr1` has type `[S; 5]`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | let [_, ref mut borrow @ .., _, mov] = arr1;
| ---- variable moved due to use in closure
...
LL | let [_, mov1, mov2, mov3, _] = &arr1;
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `arr2`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:43:10
|
LL | let arr2 = [S, S, S];
| ---- move occurs because `arr2` has type `[S; 3]`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | let [mov @ .., ref borrow] = arr2;
| ---- variable moved due to use in closure
...
LL | drop(&arr2);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `arr3`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:44:36
|
LL | let arr3 = [S, S, S, S, S];
| ---- move occurs because `arr3` has type `[S; 5]`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | let [_, ref borrow @ .., _, mov] = arr3;
| ---- variable moved due to use in closure
...
LL | let [_, mov1, mov2, mov3, _] = &arr3;
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup0`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:75:10
|
LL | let mut tup0: Option<(S, S)> = None;
| -------- move occurs because `tup0` has type `Option<(S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
LL | m!((ref mut borrow, mov) = tup0);
| ---- variable moved due to use in closure
...
LL | drop(&tup0);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!((ref mut borrow, mov) = tup0);
| ---- you could clone this value
error[E0382]: borrow of moved value: `tup1`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:76:10
|
LL | let mut tup1: Option<(S, S, S)> = None;
| -------- move occurs because `tup1` has type `Option<(S, S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
LL | m!((ref mut borrow, mov) = tup0);
LL | m!((mov, _, ref mut borrow) = tup1);
| ---- variable moved due to use in closure
...
LL | drop(&tup1);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!((mov, _, ref mut borrow) = tup1);
| ---- you could clone this value
error[E0382]: borrow of moved value: `tup2`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:77:10
|
LL | let tup2: Option<(S, S)> = None;
| ---- move occurs because `tup2` has type `Option<(S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!((ref borrow, mov) = tup2);
| ---- variable moved due to use in closure
...
LL | drop(&tup2);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!((ref borrow, mov) = tup2);
| ---- you could clone this value
error[E0382]: borrow of moved value: `tup3`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:78:10
|
LL | let tup3: Option<(S, S, S)> = None;
| ---- move occurs because `tup3` has type `Option<(S, S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!((mov, _, ref borrow) = tup3);
| ---- variable moved due to use in closure
...
LL | drop(&tup3);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!((mov, _, ref borrow) = tup3);
| ---- you could clone this value
error[E0382]: borrow of moved value: `tup4`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:79:21
|
LL | let tup4: Option<(S, S)> = None;
| ---- move occurs because `tup4` has type `Option<(S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!((ref borrow, mov) = tup4);
| ---- variable moved due to use in closure
...
LL | m!((ref x, _) = &tup4);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!((ref borrow, mov) = tup4);
| ---- you could clone this value
error[E0382]: borrow of moved value: `arr0`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:80:10
|
LL | let mut arr0: Option<[S; 3]> = None;
| -------- move occurs because `arr0` has type `Option<[S; 3]>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!([mov @ .., ref borrow] = arr0);
| ---- variable moved due to use in closure
...
LL | drop(&arr0);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!([mov @ .., ref borrow] = arr0);
| ---- you could clone this value
error[E0382]: borrow of moved value: `arr1`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:81:35
|
LL | let mut arr1: Option<[S; 5]> = None;
| -------- move occurs because `arr1` has type `Option<[S; 5]>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!([_, ref mut borrow @ .., _, mov] = arr1);
| ---- variable moved due to use in closure
...
LL | m!([_, mov1, mov2, mov3, _] = &arr1);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!([_, ref mut borrow @ .., _, mov] = arr1);
| ---- you could clone this value
error[E0382]: borrow of moved value: `arr2`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:82:10
|
LL | let arr2: Option<[S; 3]> = None;
| ---- move occurs because `arr2` has type `Option<[S; 3]>`, which does not implement the `Copy` trait
LL | let arr3: Option<[S; 5]> = None;
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!([mov @ .., ref borrow] = arr2);
| ---- variable moved due to use in closure
...
LL | drop(&arr2);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!([mov @ .., ref borrow] = arr2);
| ---- you could clone this value
error[E0382]: borrow of moved value: `arr3`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:83:35
|
LL | let arr3: Option<[S; 5]> = None;
| ---- move occurs because `arr3` has type `Option<[S; 5]>`, which does not implement the `Copy` trait
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!([_, ref borrow @ .., _, mov] = arr3);
| ---- variable moved due to use in closure
...
LL | m!([_, mov1, mov2, mov3, _] = &arr3);
| ^^^^^ value borrowed here after move
|
note: if `S` implemented `Clone`, you could clone the value
--> $DIR/move-ref-patterns-closure-captures-inside.rs:2:5
|
LL | struct S; // Not `Copy`.
| ^^^^^^^^ consider implementing `Clone` for this type
...
LL | m!([_, ref borrow @ .., _, mov] = arr3);
| ---- you could clone this value
error[E0382]: borrow of moved value: `tup0`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:111:10
|
LL | let mut tup0: Option<(S, S)> = None;
| -------- move occurs because `tup0` has type `Option<(S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
LL | m!((ref mut borrow, mov) = tup0);
| ---- variable moved due to use in closure
...
LL | drop(&tup0);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup1`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:112:10
|
LL | let mut tup1: Option<(S, S, S)> = None;
| -------- move occurs because `tup1` has type `Option<(S, S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
LL | m!((ref mut borrow, mov) = tup0);
LL | m!((mov, _, ref mut borrow) = tup1);
| ---- variable moved due to use in closure
...
LL | drop(&tup1);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup2`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:113:10
|
LL | let tup2: Option<(S, S)> = None;
| ---- move occurs because `tup2` has type `Option<(S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!((ref borrow, mov) = tup2);
| ---- variable moved due to use in closure
...
LL | drop(&tup2);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup3`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:114:10
|
LL | let tup3: Option<(S, S, S)> = None;
| ---- move occurs because `tup3` has type `Option<(S, S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!((mov, _, ref borrow) = tup3);
| ---- variable moved due to use in closure
...
LL | drop(&tup3);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `tup4`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:115:21
|
LL | let tup4: Option<(S, S)> = None;
| ---- move occurs because `tup4` has type `Option<(S, S)>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!((ref borrow, mov) = tup4);
| ---- variable moved due to use in closure
...
LL | m!((ref x, _) = &tup4);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `arr0`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:116:10
|
LL | let mut arr0: Option<[S; 3]> = None;
| -------- move occurs because `arr0` has type `Option<[S; 3]>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!([mov @ .., ref borrow] = arr0);
| ---- variable moved due to use in closure
...
LL | drop(&arr0);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `arr1`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:117:35
|
LL | let mut arr1: Option<[S; 5]> = None;
| -------- move occurs because `arr1` has type `Option<[S; 5]>`, which does not implement the `Copy` trait
...
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!([_, ref mut borrow @ .., _, mov] = arr1);
| ---- variable moved due to use in closure
...
LL | m!([_, mov1, mov2, mov3, _] = &arr1);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `arr2`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:118:10
|
LL | let arr2: Option<[S; 3]> = None;
| ---- move occurs because `arr2` has type `Option<[S; 3]>`, which does not implement the `Copy` trait
LL | let arr3: Option<[S; 5]> = None;
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!([mov @ .., ref borrow] = arr2);
| ---- variable moved due to use in closure
...
LL | drop(&arr2);
| ^^^^^ value borrowed here after move
error[E0382]: borrow of moved value: `arr3`
--> $DIR/move-ref-patterns-closure-captures-inside.rs:119:35
|
LL | let arr3: Option<[S; 5]> = None;
| ---- move occurs because `arr3` has type `Option<[S; 5]>`, which does not implement the `Copy` trait
LL | let mut closure = || {
| -- value moved into closure here
...
LL | m!([_, ref borrow @ .., _, mov] = arr3);
| ---- variable moved due to use in closure
...
LL | m!([_, mov1, mov2, mov3, _] = &arr3);
| ^^^^^ value borrowed here after move
error: aborting due to 27 previous errors
For more information about this error, try `rustc --explain E0382`.