mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #87460 - FabianWolff:issue-87456, r=Aaron1011
Point to closure when emitting 'cannot move out' for captured variable Attempts to fix #87456. The error message now points to the capturing closure, but I was not able to explain _why_ the closure implements `Fn` or `FnMut` (`TypeckResults::closure_kind_origins` did not contain anything for the closure in question). cc `@Aaron1011`
This commit is contained in:
commit
aed7f00097
@ -336,15 +336,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
if def_id.as_local() == Some(self.mir_def_id()) && upvar_field.is_some() =>
|
||||
{
|
||||
let closure_kind_ty = closure_substs.as_closure().kind_ty();
|
||||
let closure_kind = closure_kind_ty.to_opt_closure_kind();
|
||||
let capture_description = match closure_kind {
|
||||
Some(ty::ClosureKind::Fn) => "captured variable in an `Fn` closure",
|
||||
Some(ty::ClosureKind::FnMut) => "captured variable in an `FnMut` closure",
|
||||
let closure_kind = match closure_kind_ty.to_opt_closure_kind() {
|
||||
Some(kind @ (ty::ClosureKind::Fn | ty::ClosureKind::FnMut)) => kind,
|
||||
Some(ty::ClosureKind::FnOnce) => {
|
||||
bug!("closure kind does not match first argument type")
|
||||
}
|
||||
None => bug!("closure kind not inferred by borrowck"),
|
||||
};
|
||||
let capture_description =
|
||||
format!("captured variable in an `{}` closure", closure_kind);
|
||||
|
||||
let upvar = &self.upvars[upvar_field.unwrap().index()];
|
||||
let upvar_hir_id = upvar.place.get_root_variable();
|
||||
@ -368,6 +368,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
let mut diag = self.cannot_move_out_of(span, &place_description);
|
||||
|
||||
diag.span_label(upvar_span, "captured outer variable");
|
||||
diag.span_label(
|
||||
self.body.span,
|
||||
format!("captured by this `{}` closure", closure_kind),
|
||||
);
|
||||
|
||||
diag
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ error[E0507]: cannot move out of `x`, a captured variable in an `Fn` closure
|
||||
LL | let x = Box::new(0);
|
||||
| - captured outer variable
|
||||
LL | Box::new(|| x)
|
||||
| ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| ---^
|
||||
| | |
|
||||
| | move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| captured by this `Fn` closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,15 +1,18 @@
|
||||
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 3;
|
||||
| --- captured outer variable
|
||||
LL | let _g = to_fn_mut(|| {
|
||||
LL | let _h = to_fn_once(move || -> isize { *bar });
|
||||
| ^^^^^^^^^^^^^^^^ ----
|
||||
| | |
|
||||
| | move occurs because `bar` has type `Box<isize>`, which does not implement the `Copy` trait
|
||||
| | move occurs due to use in closure
|
||||
| move out of `bar` occurs here
|
||||
LL | let bar: Box<_> = box 3;
|
||||
| --- captured outer variable
|
||||
LL | let _g = to_fn_mut(|| {
|
||||
| ________________________-
|
||||
LL | | let _h = to_fn_once(move || -> isize { *bar });
|
||||
| | ^^^^^^^^^^^^^^^^ ----
|
||||
| | | |
|
||||
| | | move occurs because `bar` has type `Box<isize>`, which does not implement the `Copy` trait
|
||||
| | | move occurs due to use in closure
|
||||
| | move out of `bar` occurs here
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
14
src/test/ui/borrowck/issue-87456-point-to-closure.rs
Normal file
14
src/test/ui/borrowck/issue-87456-point-to-closure.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Regression test for #87456.
|
||||
|
||||
fn take_mut(_val: impl FnMut()) {}
|
||||
|
||||
fn main() {
|
||||
let val = String::new();
|
||||
//~^ NOTE: captured outer variable
|
||||
take_mut(|| {
|
||||
//~^ NOTE: captured by this `FnMut` closure
|
||||
let _foo: String = val;
|
||||
//~^ ERROR: cannot move out of `val`, a captured variable in an `FnMut` closure [E0507]
|
||||
//~| NOTE: move occurs because
|
||||
})
|
||||
}
|
22
src/test/ui/borrowck/issue-87456-point-to-closure.stderr
Normal file
22
src/test/ui/borrowck/issue-87456-point-to-closure.stderr
Normal file
@ -0,0 +1,22 @@
|
||||
error[E0507]: cannot move out of `val`, a captured variable in an `FnMut` closure
|
||||
--> $DIR/issue-87456-point-to-closure.rs:10:28
|
||||
|
|
||||
LL | let val = String::new();
|
||||
| --- captured outer variable
|
||||
LL |
|
||||
LL | take_mut(|| {
|
||||
| ______________-
|
||||
LL | |
|
||||
LL | | let _foo: String = val;
|
||||
| | ^^^
|
||||
| | |
|
||||
| | move occurs because `val` has type `String`, which does not implement the `Copy` trait
|
||||
| | help: consider borrowing here: `&val`
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | })
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0507`.
|
@ -1,11 +1,15 @@
|
||||
error[E0507]: cannot move out of `y`, a captured variable in an `Fn` closure
|
||||
--> $DIR/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:11:9
|
||||
|
|
||||
LL | let y = vec![format!("World")];
|
||||
| - captured outer variable
|
||||
LL | call(|| {
|
||||
LL | y.into_iter();
|
||||
| ^ move occurs because `y` has type `Vec<String>`, which does not implement the `Copy` trait
|
||||
LL | let y = vec![format!("World")];
|
||||
| - captured outer variable
|
||||
LL | call(|| {
|
||||
| __________-
|
||||
LL | | y.into_iter();
|
||||
| | ^ move occurs because `y` has type `Vec<String>`, which does not implement the `Copy` trait
|
||||
LL | |
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -4,7 +4,10 @@ error[E0507]: cannot move out of `*v`, as `v` is a captured variable in an `FnMu
|
||||
LL | fn f<'r, T>(v: &'r T) -> Box<dyn FnMut() -> T + 'r> {
|
||||
| - captured outer variable
|
||||
LL | id(Box::new(|| *v))
|
||||
| ^^ move occurs because `*v` has type `T`, which does not implement the `Copy` trait
|
||||
| ---^^
|
||||
| | |
|
||||
| | move occurs because `*v` has type `T`, which does not implement the `Copy` trait
|
||||
| captured by this `FnMut` closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -4,7 +4,10 @@ error[E0507]: cannot move out of `i`, a captured variable in an `Fn` closure
|
||||
LL | let i = box 3;
|
||||
| - captured outer variable
|
||||
LL | let _f = to_fn(|| test(i));
|
||||
| ^ move occurs because `i` has type `Box<usize>`, which does not implement the `Copy` trait
|
||||
| --------^-
|
||||
| | |
|
||||
| | move occurs because `i` has type `Box<usize>`, which does not implement the `Copy` trait
|
||||
| captured by this `Fn` closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -4,7 +4,10 @@ error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn`
|
||||
LL | let x = (vec![22], vec![44]);
|
||||
| - captured outer variable
|
||||
LL | expect_fn(|| drop(x.0));
|
||||
| ^^^ move occurs because `x.0` has type `Vec<i32>`, which does not implement the `Copy` trait
|
||||
| --------^^^-
|
||||
| | |
|
||||
| | move occurs because `x.0` has type `Vec<i32>`, which does not implement the `Copy` trait
|
||||
| captured by this `Fn` closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -29,11 +29,17 @@ LL | f.f.call_mut(())
|
||||
error[E0507]: cannot move out of `f`, a captured variable in an `FnMut` closure
|
||||
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:57:13
|
||||
|
|
||||
LL | let mut f = move |g: Box<dyn FnMut(isize)>, b: isize| {
|
||||
| ----- captured outer variable
|
||||
LL | let mut f = move |g: Box<dyn FnMut(isize)>, b: isize| {
|
||||
| ----- captured outer variable
|
||||
...
|
||||
LL | foo(f);
|
||||
| ^ move occurs because `f` has type `[closure@$DIR/borrowck-call-is-borrow-issue-12224.rs:52:17: 54:6]`, which does not implement the `Copy` trait
|
||||
LL | f(Box::new(|a| {
|
||||
| ________________-
|
||||
LL | |
|
||||
LL | | foo(f);
|
||||
| | ^ move occurs because `f` has type `[closure@$DIR/borrowck-call-is-borrow-issue-12224.rs:52:17: 54:6]`, which does not implement the `Copy` trait
|
||||
LL | |
|
||||
LL | | }), 3);
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0505]: cannot move out of `f` because it is borrowed
|
||||
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:55:16
|
||||
|
@ -1,281 +1,487 @@
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:28:21
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | let X(_t) = x;
|
||||
| -- ^ help: consider borrowing here: `&x`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
| | -- ^ help: consider borrowing here: `&x`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:32:34
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | if let Either::One(_t) = e { }
|
||||
| -- ^ help: consider borrowing here: `&e`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | if let Either::One(_t) = e { }
|
||||
| | -- ^ help: consider borrowing here: `&e`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:36:37
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | while let Either::One(_t) = e { }
|
||||
| -- ^ help: consider borrowing here: `&e`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | while let Either::One(_t) = e { }
|
||||
| | -- ^ help: consider borrowing here: `&e`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:40:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | match e {
|
||||
| ^ help: consider borrowing here: `&e`
|
||||
...
|
||||
LL | Either::One(_t)
|
||||
| --
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match e {
|
||||
| | ^ help: consider borrowing here: `&e`
|
||||
... |
|
||||
LL | | Either::One(_t)
|
||||
| | --
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:47:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | match e {
|
||||
| ^ help: consider borrowing here: `&e`
|
||||
...
|
||||
LL | Either::One(_t) => (),
|
||||
| --
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match e {
|
||||
| | ^ help: consider borrowing here: `&e`
|
||||
... |
|
||||
LL | | Either::One(_t) => (),
|
||||
| | --
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:56:25
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | let X(mut _t) = x;
|
||||
| ------ ^ help: consider borrowing here: `&x`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | let X(mut _t) = x;
|
||||
| | ------ ^ help: consider borrowing here: `&x`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:60:38
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | if let Either::One(mut _t) = em { }
|
||||
| ------ ^^ help: consider borrowing here: `&em`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | if let Either::One(mut _t) = em { }
|
||||
| | ------ ^^ help: consider borrowing here: `&em`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:64:41
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | while let Either::One(mut _t) = em { }
|
||||
| ------ ^^ help: consider borrowing here: `&em`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | while let Either::One(mut _t) = em { }
|
||||
| | ------ ^^ help: consider borrowing here: `&em`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:68:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | match em {
|
||||
| ^^ help: consider borrowing here: `&em`
|
||||
...
|
||||
LL | Either::One(mut _t)
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match em {
|
||||
| | ^^ help: consider borrowing here: `&em`
|
||||
... |
|
||||
LL | | Either::One(mut _t)
|
||||
| | ------
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:75:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | match em {
|
||||
| ^^ help: consider borrowing here: `&em`
|
||||
...
|
||||
LL | Either::One(mut _t) => (),
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fn(|| {
|
||||
| ________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match em {
|
||||
| | ^^ help: consider borrowing here: `&em`
|
||||
... |
|
||||
LL | | Either::One(mut _t) => (),
|
||||
| | ------
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:95:21
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | let X(_t) = x;
|
||||
| -- ^ help: consider borrowing here: `&x`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
| | -- ^ help: consider borrowing here: `&x`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:99:34
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | if let Either::One(_t) = e { }
|
||||
| -- ^ help: consider borrowing here: `&e`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | if let Either::One(_t) = e { }
|
||||
| | -- ^ help: consider borrowing here: `&e`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:103:37
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | while let Either::One(_t) = e { }
|
||||
| -- ^ help: consider borrowing here: `&e`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | while let Either::One(_t) = e { }
|
||||
| | -- ^ help: consider borrowing here: `&e`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:107:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | match e {
|
||||
| ^ help: consider borrowing here: `&e`
|
||||
...
|
||||
LL | Either::One(_t)
|
||||
| --
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match e {
|
||||
| | ^ help: consider borrowing here: `&e`
|
||||
... |
|
||||
LL | | Either::One(_t)
|
||||
| | --
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:114:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | match e {
|
||||
| ^ help: consider borrowing here: `&e`
|
||||
...
|
||||
LL | Either::One(_t) => (),
|
||||
| --
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match e {
|
||||
| | ^ help: consider borrowing here: `&e`
|
||||
... |
|
||||
LL | | Either::One(_t) => (),
|
||||
| | --
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:123:25
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | let X(mut _t) = x;
|
||||
| ------ ^ help: consider borrowing here: `&x`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | let X(mut _t) = x;
|
||||
| | ------ ^ help: consider borrowing here: `&x`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:127:38
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | if let Either::One(mut _t) = em { }
|
||||
| ------ ^^ help: consider borrowing here: `&em`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | if let Either::One(mut _t) = em { }
|
||||
| | ------ ^^ help: consider borrowing here: `&em`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:131:41
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | while let Either::One(mut _t) = em { }
|
||||
| ------ ^^ help: consider borrowing here: `&em`
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | while let Either::One(mut _t) = em { }
|
||||
| | ------ ^^ help: consider borrowing here: `&em`
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:135:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | match em {
|
||||
| ^^ help: consider borrowing here: `&em`
|
||||
...
|
||||
LL | Either::One(mut _t)
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match em {
|
||||
| | ^^ help: consider borrowing here: `&em`
|
||||
... |
|
||||
LL | | Either::One(mut _t)
|
||||
| | ------
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:142:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | match em {
|
||||
| ^^ help: consider borrowing here: `&em`
|
||||
...
|
||||
LL | Either::One(mut _t) => (),
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match em {
|
||||
| | ^^ help: consider borrowing here: `&em`
|
||||
... |
|
||||
LL | | Either::One(mut _t) => (),
|
||||
| | ------
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:150:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | match em {
|
||||
| ^^ help: consider borrowing here: `&em`
|
||||
...
|
||||
LL | Either::One(mut _t) => (),
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
LL | consume_fnmut(|| {
|
||||
| ___________________-
|
||||
LL | | let X(_t) = x;
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | | match em {
|
||||
| | ^^ help: consider borrowing here: `&em`
|
||||
... |
|
||||
LL | | Either::One(mut _t) => (),
|
||||
| | ------
|
||||
| | |
|
||||
| | data moved here
|
||||
| | move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
... |
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error: aborting due to 21 previous errors
|
||||
|
||||
|
@ -1,17 +1,22 @@
|
||||
error[E0507]: cannot move out of `var`, a captured variable in an `FnMut` closure
|
||||
--> $DIR/option-content-move2.rs:9:9
|
||||
|
|
||||
LL | let mut var = None;
|
||||
| ------- captured outer variable
|
||||
...
|
||||
LL | move || {
|
||||
| ^^^^^^^ move out of `var` occurs here
|
||||
LL |
|
||||
LL | var = Some(NotCopyable);
|
||||
| ---
|
||||
| |
|
||||
| move occurs because `var` has type `Option<NotCopyable>`, which does not implement the `Copy` trait
|
||||
| move occurs due to use in closure
|
||||
LL | let mut var = None;
|
||||
| ------- captured outer variable
|
||||
LL | func(|| {
|
||||
| __________-
|
||||
LL | | // Shouldn't suggest `move ||.as_ref()` here
|
||||
LL | | move || {
|
||||
| | ^^^^^^^ move out of `var` occurs here
|
||||
LL | |
|
||||
LL | | var = Some(NotCopyable);
|
||||
| | ---
|
||||
| | |
|
||||
| | move occurs because `var` has type `Option<NotCopyable>`, which does not implement the `Copy` trait
|
||||
| | move occurs due to use in closure
|
||||
LL | | }
|
||||
LL | | });
|
||||
| |_____- captured by this `FnMut` closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -4,7 +4,10 @@ error[E0507]: cannot move out of `x`, a captured variable in an `Fn` closure
|
||||
LL | let x = Box::new(0);
|
||||
| - captured outer variable
|
||||
LL | let f = to_fn(|| drop(x));
|
||||
| ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| --------^-
|
||||
| | |
|
||||
| | move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `x`, a captured variable in an `FnMut` closure
|
||||
--> $DIR/unboxed-closure-illegal-move.rs:19:35
|
||||
@ -12,7 +15,10 @@ error[E0507]: cannot move out of `x`, a captured variable in an `FnMut` closure
|
||||
LL | let x = Box::new(0);
|
||||
| - captured outer variable
|
||||
LL | let f = to_fn_mut(|| drop(x));
|
||||
| ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| --------^-
|
||||
| | |
|
||||
| | move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| captured by this `FnMut` closure
|
||||
|
||||
error[E0507]: cannot move out of `x`, a captured variable in an `Fn` closure
|
||||
--> $DIR/unboxed-closure-illegal-move.rs:28:36
|
||||
@ -20,7 +26,10 @@ error[E0507]: cannot move out of `x`, a captured variable in an `Fn` closure
|
||||
LL | let x = Box::new(0);
|
||||
| - captured outer variable
|
||||
LL | let f = to_fn(move || drop(x));
|
||||
| ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| -------------^-
|
||||
| | |
|
||||
| | move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| captured by this `Fn` closure
|
||||
|
||||
error[E0507]: cannot move out of `x`, a captured variable in an `FnMut` closure
|
||||
--> $DIR/unboxed-closure-illegal-move.rs:32:40
|
||||
@ -28,7 +37,10 @@ error[E0507]: cannot move out of `x`, a captured variable in an `FnMut` closure
|
||||
LL | let x = Box::new(0);
|
||||
| - captured outer variable
|
||||
LL | let f = to_fn_mut(move || drop(x));
|
||||
| ^ move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| -------------^-
|
||||
| | |
|
||||
| | move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
|
||||
| captured by this `FnMut` closure
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user