mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
ad9a5a5f9f
``` error[E0507]: cannot move out of `bar`, a captured variable in an `FnMut` closure --> $DIR/borrowck-move-by-capture.rs:9:29 | LL | let bar: Box<_> = Box::new(3); | --- captured outer variable LL | let _g = to_fn_mut(|| { | -- captured by this `FnMut` closure LL | let _h = to_fn_once(move || -> isize { *bar }); | ^^^^^^^^^^^^^^^^ ---- | | | | | variable moved due to use in closure | | move occurs because `bar` has type `Box<isize>`, which does not implement the `Copy` trait | `bar` is moved here | help: clone the value before moving it into the closure | LL ~ let value = bar.clone(); LL ~ let _h = to_fn_once(move || -> isize { value }); | ```
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`.
|