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
```
117 lines
4.2 KiB
Text
117 lines
4.2 KiB
Text
error[E0382]: use of moved value: `u`
|
|
--> $DIR/borrowck-union-move.rs:26:21
|
|
|
|
|
LL | let mut u = Unn { n1: ManuallyDrop::new(NonCopy) };
|
|
| ----- move occurs because `u` has type `Unn`, which does not implement the `Copy` trait
|
|
LL | let a = u.n1;
|
|
| ---- value moved here
|
|
LL | let a = u.n1;
|
|
| ^^^^ value used here after move
|
|
|
|
|
note: if `Unn` implemented `Clone`, you could clone the value
|
|
--> $DIR/borrowck-union-move.rs:7:1
|
|
|
|
|
LL | union Unn {
|
|
| ^^^^^^^^^ consider implementing `Clone` for this type
|
|
...
|
|
LL | let a = u.n1;
|
|
| ---- you could clone this value
|
|
|
|
error[E0382]: use of moved value: `u`
|
|
--> $DIR/borrowck-union-move.rs:31:21
|
|
|
|
|
LL | let mut u = Unn { n1: ManuallyDrop::new(NonCopy) };
|
|
| ----- move occurs because `u` has type `Unn`, which does not implement the `Copy` trait
|
|
LL | let a = u.n1;
|
|
| ---- value moved here
|
|
LL | let a = u;
|
|
| ^ value used here after move
|
|
|
|
|
note: if `Unn` implemented `Clone`, you could clone the value
|
|
--> $DIR/borrowck-union-move.rs:7:1
|
|
|
|
|
LL | union Unn {
|
|
| ^^^^^^^^^ consider implementing `Clone` for this type
|
|
...
|
|
LL | let a = u.n1;
|
|
| ---- you could clone this value
|
|
|
|
error[E0382]: use of moved value: `u`
|
|
--> $DIR/borrowck-union-move.rs:36:21
|
|
|
|
|
LL | let mut u = Unn { n1: ManuallyDrop::new(NonCopy) };
|
|
| ----- move occurs because `u` has type `Unn`, which does not implement the `Copy` trait
|
|
LL | let a = u.n1;
|
|
| ---- value moved here
|
|
LL | let a = u.n2;
|
|
| ^^^^ value used here after move
|
|
|
|
|
note: if `Unn` implemented `Clone`, you could clone the value
|
|
--> $DIR/borrowck-union-move.rs:7:1
|
|
|
|
|
LL | union Unn {
|
|
| ^^^^^^^^^ consider implementing `Clone` for this type
|
|
...
|
|
LL | let a = u.n1;
|
|
| ---- you could clone this value
|
|
|
|
error[E0382]: use of moved value: `u`
|
|
--> $DIR/borrowck-union-move.rs:63:21
|
|
|
|
|
LL | let mut u = Ucn { c: Copy };
|
|
| ----- move occurs because `u` has type `Ucn`, which does not implement the `Copy` trait
|
|
LL | let a = u.n;
|
|
| --- value moved here
|
|
LL | let a = u.n;
|
|
| ^^^ value used here after move
|
|
|
|
|
note: if `Ucn` implemented `Clone`, you could clone the value
|
|
--> $DIR/borrowck-union-move.rs:15:1
|
|
|
|
|
LL | union Ucn {
|
|
| ^^^^^^^^^ consider implementing `Clone` for this type
|
|
...
|
|
LL | let a = u.n;
|
|
| --- you could clone this value
|
|
|
|
error[E0382]: use of moved value: `u`
|
|
--> $DIR/borrowck-union-move.rs:68:21
|
|
|
|
|
LL | let mut u = Ucn { c: Copy };
|
|
| ----- move occurs because `u` has type `Ucn`, which does not implement the `Copy` trait
|
|
LL | let a = u.n;
|
|
| --- value moved here
|
|
LL | let a = u.c;
|
|
| ^^^ value used here after move
|
|
|
|
|
note: if `Ucn` implemented `Clone`, you could clone the value
|
|
--> $DIR/borrowck-union-move.rs:15:1
|
|
|
|
|
LL | union Ucn {
|
|
| ^^^^^^^^^ consider implementing `Clone` for this type
|
|
...
|
|
LL | let a = u.n;
|
|
| --- you could clone this value
|
|
|
|
error[E0382]: use of moved value: `u`
|
|
--> $DIR/borrowck-union-move.rs:83:21
|
|
|
|
|
LL | let mut u = Ucn { c: Copy };
|
|
| ----- move occurs because `u` has type `Ucn`, which does not implement the `Copy` trait
|
|
LL | let a = u.n;
|
|
| --- value moved here
|
|
LL | let a = u;
|
|
| ^ value used here after move
|
|
|
|
|
note: if `Ucn` implemented `Clone`, you could clone the value
|
|
--> $DIR/borrowck-union-move.rs:15:1
|
|
|
|
|
LL | union Ucn {
|
|
| ^^^^^^^^^ consider implementing `Clone` for this type
|
|
...
|
|
LL | let a = u.n;
|
|
| --- you could clone this value
|
|
|
|
error: aborting due to 6 previous errors
|
|
|
|
For more information about this error, try `rustc --explain E0382`.
|