mirror of https://github.com/rust-lang/rust.git
96 lines
3.3 KiB
Plaintext
96 lines
3.3 KiB
Plaintext
error[E0507]: cannot move out of `var`, a captured variable in an `FnMut` closure
|
|
--> $DIR/option-content-move3.rs:13:21
|
|
|
|
|
LL | let var = NotCopyable;
|
|
| --- captured outer variable
|
|
...
|
|
LL | move || {
|
|
| ------- captured by this `FnMut` closure
|
|
LL | let x = var;
|
|
| ^^^ move occurs because `var` has type `NotCopyable`, which does not implement the `Copy` trait
|
|
|
|
|
note: if `NotCopyable` implemented `Clone`, you could clone the value
|
|
--> $DIR/option-content-move3.rs:2:1
|
|
|
|
|
LL | struct NotCopyable;
|
|
| ^^^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type
|
|
...
|
|
LL | let x = var;
|
|
| --- you could clone this value
|
|
help: consider borrowing here
|
|
|
|
|
LL | let x = &var;
|
|
| +
|
|
|
|
error[E0507]: cannot move out of `var`, a captured variable in an `FnMut` closure
|
|
--> $DIR/option-content-move3.rs:12:9
|
|
|
|
|
LL | let var = NotCopyable;
|
|
| --- captured outer variable
|
|
LL | func(|| {
|
|
| -- captured by this `FnMut` closure
|
|
LL | // Shouldn't suggest `move ||.as_ref()` here
|
|
LL | move || {
|
|
| ^^^^^^^ `var` is moved here
|
|
LL | let x = var;
|
|
| ---
|
|
| |
|
|
| variable moved due to use in closure
|
|
| move occurs because `var` has type `NotCopyable`, which does not implement the `Copy` trait
|
|
|
|
|
note: if `NotCopyable` implemented `Clone`, you could clone the value
|
|
--> $DIR/option-content-move3.rs:2:1
|
|
|
|
|
LL | struct NotCopyable;
|
|
| ^^^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type
|
|
...
|
|
LL | let x = var;
|
|
| --- you could clone this value
|
|
|
|
error[E0507]: cannot move out of `var`, a captured variable in an `FnMut` closure
|
|
--> $DIR/option-content-move3.rs:24:21
|
|
|
|
|
LL | let var = NotCopyableButCloneable;
|
|
| --- captured outer variable
|
|
...
|
|
LL | move || {
|
|
| ------- captured by this `FnMut` closure
|
|
LL | let x = var;
|
|
| ^^^ move occurs because `var` has type `NotCopyableButCloneable`, which does not implement the `Copy` trait
|
|
|
|
|
help: consider borrowing here
|
|
|
|
|
LL | let x = &var;
|
|
| +
|
|
|
|
error[E0507]: cannot move out of `var`, a captured variable in an `FnMut` closure
|
|
--> $DIR/option-content-move3.rs:23:9
|
|
|
|
|
LL | let var = NotCopyableButCloneable;
|
|
| --- captured outer variable
|
|
LL | func(|| {
|
|
| -- captured by this `FnMut` closure
|
|
LL | // Shouldn't suggest `move ||.as_ref()` here
|
|
LL | move || {
|
|
| ^^^^^^^ `var` is moved here
|
|
LL | let x = var;
|
|
| ---
|
|
| |
|
|
| variable moved due to use in closure
|
|
| move occurs because `var` has type `NotCopyableButCloneable`, which does not implement the `Copy` trait
|
|
|
|
|
help: clone the value before moving it into the closure
|
|
|
|
|
LL ~ {
|
|
LL + let value = var.clone();
|
|
LL ~ move || {
|
|
LL ~ let x = value;
|
|
LL | println!("{x:?}");
|
|
LL ~ }
|
|
LL + }
|
|
|
|
|
|
|
error: aborting due to 4 previous errors
|
|
|
|
For more information about this error, try `rustc --explain E0507`.
|