Rollup merge of #144558 - estebank:issue-68119, r=lcnr
Point at the `Fn()` or `FnMut()` bound that coerced a closure, which caused a move error
When encountering a move error involving a closure because the captured value isn't `Copy`, and the obligation comes from a bound on a type parameter that requires `Fn` or `FnMut`, we point at it and explain that an `FnOnce` wouldn't cause the move error.
```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
--> f111.rs:15:25
|
14 | fn do_stuff(foo: Option<Foo>) {
| --- ----------- move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
| |
| captured outer variable
15 | require_fn_trait(|| async {
| -- ^^^^^ `foo` is moved here
| |
| captured by this `Fn` closure
16 | if foo.map_or(false, |f| f.foo()) {
| --- variable moved due to use in coroutine
|
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
--> f111.rs:12:53
|
12 | fn require_fn_trait<F: Future<Output = ()>>(_: impl Fn() -> F) {}
| ^^^^^^^^^
help: consider cloning the value if the performance cost is acceptable
|
16 | if foo.clone().map_or(false, |f| f.foo()) {
| ++++++++
```
Fix rust-lang/rust#68119, by pointing at `Fn` and `FnMut` bounds involved in move errors.
This commit is contained in:
commit
907076c3dd
16 changed files with 941 additions and 26 deletions
|
|
@ -9,7 +9,8 @@ use rustc_middle::bug;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex};
|
||||
use rustc_span::{BytePos, ExpnKind, MacroKind, Span};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::{BytePos, DUMMY_SP, ExpnKind, MacroKind, Span};
|
||||
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use tracing::debug;
|
||||
|
|
@ -507,12 +508,18 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
);
|
||||
|
||||
let closure_span = tcx.def_span(def_id);
|
||||
|
||||
self.cannot_move_out_of(span, &place_description)
|
||||
.with_span_label(upvar_span, "captured outer variable")
|
||||
.with_span_label(
|
||||
closure_span,
|
||||
format!("captured by this `{closure_kind}` closure"),
|
||||
)
|
||||
.with_span_help(
|
||||
self.get_closure_bound_clause_span(*def_id),
|
||||
"`Fn` and `FnMut` closures require captured values to be able to be \
|
||||
consumed multiple times, but an `FnOnce` consume them only once",
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
let source = self.borrowed_content_source(deref_base);
|
||||
|
|
@ -561,6 +568,47 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
err
|
||||
}
|
||||
|
||||
fn get_closure_bound_clause_span(&self, def_id: DefId) -> Span {
|
||||
let tcx = self.infcx.tcx;
|
||||
let typeck_result = tcx.typeck(self.mir_def_id());
|
||||
// Check whether the closure is an argument to a call, if so,
|
||||
// get the instantiated where-bounds of that call.
|
||||
let closure_hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local());
|
||||
let hir::Node::Expr(parent) = tcx.parent_hir_node(closure_hir_id) else { return DUMMY_SP };
|
||||
|
||||
let predicates = match parent.kind {
|
||||
hir::ExprKind::Call(callee, _) => {
|
||||
let Some(ty) = typeck_result.node_type_opt(callee.hir_id) else { return DUMMY_SP };
|
||||
let ty::FnDef(fn_def_id, args) = ty.kind() else { return DUMMY_SP };
|
||||
tcx.predicates_of(fn_def_id).instantiate(tcx, args)
|
||||
}
|
||||
hir::ExprKind::MethodCall(..) => {
|
||||
let Some((_, method)) = typeck_result.type_dependent_def(parent.hir_id) else {
|
||||
return DUMMY_SP;
|
||||
};
|
||||
let args = typeck_result.node_args(parent.hir_id);
|
||||
tcx.predicates_of(method).instantiate(tcx, args)
|
||||
}
|
||||
_ => return DUMMY_SP,
|
||||
};
|
||||
|
||||
// Check whether one of the where-bounds requires the closure to impl `Fn[Mut]`.
|
||||
for (pred, span) in predicates.predicates.iter().zip(predicates.spans.iter()) {
|
||||
if let Some(clause) = pred.as_trait_clause()
|
||||
&& let ty::Closure(clause_closure_def_id, _) = clause.self_ty().skip_binder().kind()
|
||||
&& *clause_closure_def_id == def_id
|
||||
&& (tcx.lang_items().fn_mut_trait() == Some(clause.def_id())
|
||||
|| tcx.lang_items().fn_trait() == Some(clause.def_id()))
|
||||
{
|
||||
// Found `<TyOfCapturingClosure as FnMut>`
|
||||
// We point at the `Fn()` or `FnMut()` bound that coerced the closure, which
|
||||
// could be changed to `FnOnce()` to avoid the move error.
|
||||
return *span;
|
||||
}
|
||||
}
|
||||
DUMMY_SP
|
||||
}
|
||||
|
||||
fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diag<'_>, span: Span) {
|
||||
match error {
|
||||
GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => {
|
||||
|
|
|
|||
|
|
@ -847,17 +847,18 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
|
|||
self
|
||||
}
|
||||
|
||||
with_fn! { with_span_help,
|
||||
/// Prints the span with some help above it.
|
||||
/// This is like [`Diag::help()`], but it gets its own span.
|
||||
#[rustc_lint_diagnostics]
|
||||
pub fn span_help<S: Into<MultiSpan>>(
|
||||
pub fn span_help(
|
||||
&mut self,
|
||||
sp: S,
|
||||
sp: impl Into<MultiSpan>,
|
||||
msg: impl Into<SubdiagMessage>,
|
||||
) -> &mut Self {
|
||||
self.sub(Level::Help, msg, sp.into());
|
||||
self
|
||||
}
|
||||
} }
|
||||
|
||||
/// Disallow attaching suggestions to this diagnostic.
|
||||
/// Any suggestions attached e.g. with the `span_suggestion_*` methods
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ LL | Box::new(|| x)
|
|||
| |
|
||||
| captured by this `Fn` closure
|
||||
|
|
||||
= help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | Box::new(|| x.clone())
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ LL | let _h = to_fn_once(move || -> isize { *bar });
|
|||
| |
|
||||
| `bar` is moved here
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/borrowck-move-by-capture.rs:3:37
|
||||
|
|
||||
LL | fn to_fn_mut<A:std::marker::Tuple,F:FnMut<A>>(f: F) -> F { f }
|
||||
| ^^^^^^^^
|
||||
help: consider cloning the value before moving it into the closure
|
||||
|
|
||||
LL ~ let value = bar.clone();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ LL |
|
|||
LL | self.b;
|
||||
| ^^^^^^ `self.b` is moved here
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/issue-103624.rs:7:36
|
||||
|
|
||||
LL | async fn spawn_blocking<T>(f: impl (Fn() -> T) + Send + Sync + 'static) -> T {
|
||||
| ^^^^^^^^^^^
|
||||
note: if `StructB` implemented `Clone`, you could clone the value
|
||||
--> $DIR/issue-103624.rs:23:1
|
||||
|
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ LL |
|
|||
LL | let _foo: String = val;
|
||||
| ^^^ move occurs because `val` has type `String`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/issue-87456-point-to-closure.rs:3:24
|
||||
|
|
||||
LL | fn take_mut(_val: impl FnMut()) {}
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let _foo: String = &val;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ LL | y.into_iter();
|
|||
| |
|
||||
| move occurs because `y` has type `Vec<String>`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:5:28
|
||||
|
|
||||
LL | fn call<F>(f: F) where F : Fn() {
|
||||
| ^^^^
|
||||
note: `into_iter` takes ownership of the receiver `self`, which moves `y`
|
||||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
||||
help: you can `clone` the value and consume it, but this might not be your desired behavior
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ LL | id(Box::new(|| *v))
|
|||
| |
|
||||
| captured by this `FnMut` closure
|
||||
|
|
||||
= help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
help: if `T` implemented `Clone`, you could clone the value
|
||||
--> $DIR/issue-4335.rs:5:10
|
||||
|
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ LL | let _f = to_fn(|| test(i));
|
|||
| |
|
||||
| captured by this `Fn` closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/moves-based-on-type-move-out-of-closure-env-issue-1965.rs:3:33
|
||||
|
|
||||
LL | fn to_fn<A:std::marker::Tuple,F:Fn<A>>(f: F) -> F { f }
|
||||
| ^^^^^
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | let _f = to_fn(|| test(i.clone()));
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ LL | expect_fn(|| drop(x.0));
|
|||
| |
|
||||
| captured by this `Fn` closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/issue-52663-span-decl-captured-variable.rs:1:33
|
||||
|
|
||||
LL | fn expect_fn<F>(f: F) where F : Fn() {
|
||||
| ^^^^
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | expect_fn(|| drop(x.0.clone()));
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ LL |
|
|||
LL | foo(f);
|
||||
| ^ move occurs because `f` has type `{closure@$DIR/borrowck-call-is-borrow-issue-12224.rs:52:17: 52:58}`, which does not implement the `Copy` trait
|
||||
|
|
||||
= help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | foo(f.clone());
|
||||
|
|
|
|||
|
|
@ -11,8 +11,55 @@ struct X(Y);
|
|||
struct Y;
|
||||
|
||||
fn consume_fn<F: Fn()>(_f: F) { }
|
||||
//~^ HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
|
||||
fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
//~^ HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
|
||||
trait T {
|
||||
fn consume_fn<F: Fn()>(_f: F) { }
|
||||
//~^ HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
//~^ HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
//~| HELP `Fn` and `FnMut` closures
|
||||
}
|
||||
impl T for () {}
|
||||
|
||||
pub fn main() { }
|
||||
|
||||
|
|
@ -73,6 +120,120 @@ fn move_into_fn() {
|
|||
});
|
||||
}
|
||||
|
||||
fn move_into_assoc_fn() {
|
||||
let e = Either::One(X(Y));
|
||||
let mut em = Either::One(X(Y));
|
||||
|
||||
let x = X(Y);
|
||||
|
||||
// move into Fn
|
||||
|
||||
<() as T>::consume_fn(|| {
|
||||
let X(_t) = x;
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
if let Either::One(_t) = e { }
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
while let Either::One(_t) = e { }
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
match e {
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
Either::One(_t)
|
||||
| Either::Two(_t) => (),
|
||||
}
|
||||
match e {
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
Either::One(_t) => (),
|
||||
Either::Two(ref _t) => (),
|
||||
// FIXME: should suggest removing `ref` too
|
||||
}
|
||||
|
||||
let X(mut _t) = x;
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
if let Either::One(mut _t) = em { }
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
while let Either::One(mut _t) = em { }
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
match em {
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
Either::One(mut _t)
|
||||
| Either::Two(mut _t) => (),
|
||||
}
|
||||
match em {
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
Either::One(mut _t) => (),
|
||||
Either::Two(ref _t) => (),
|
||||
// FIXME: should suggest removing `ref` too
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn move_into_method() {
|
||||
let e = Either::One(X(Y));
|
||||
let mut em = Either::One(X(Y));
|
||||
|
||||
let x = X(Y);
|
||||
|
||||
// move into Fn
|
||||
|
||||
().method_consume_fn(|| {
|
||||
let X(_t) = x;
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
if let Either::One(_t) = e { }
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
while let Either::One(_t) = e { }
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
match e {
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
Either::One(_t)
|
||||
| Either::Two(_t) => (),
|
||||
}
|
||||
match e {
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
Either::One(_t) => (),
|
||||
Either::Two(ref _t) => (),
|
||||
// FIXME: should suggest removing `ref` too
|
||||
}
|
||||
|
||||
let X(mut _t) = x;
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
if let Either::One(mut _t) = em { }
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
while let Either::One(mut _t) = em { }
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
match em {
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
Either::One(mut _t)
|
||||
| Either::Two(mut _t) => (),
|
||||
}
|
||||
match em {
|
||||
//~^ ERROR cannot move
|
||||
//~| HELP consider borrowing here
|
||||
Either::One(mut _t) => (),
|
||||
Either::Two(ref _t) => (),
|
||||
// FIXME: should suggest removing `ref` too
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn move_into_fnmut() {
|
||||
let e = Either::One(X(Y));
|
||||
let mut em = Either::One(X(Y));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
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
|
||||
--> $DIR/move-into-closure.rs:75:21
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
|
|
@ -12,13 +12,18 @@ LL | let X(_t) = x;
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let X(_t) = &x;
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:31:34
|
||||
--> $DIR/move-into-closure.rs:78:34
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
|
|
@ -32,13 +37,18 @@ LL | if let Either::One(_t) = e { }
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | if let Either::One(_t) = &e { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:34:37
|
||||
--> $DIR/move-into-closure.rs:81:37
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
|
|
@ -52,13 +62,18 @@ LL | while let Either::One(_t) = e { }
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | while let Either::One(_t) = &e { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:37:15
|
||||
--> $DIR/move-into-closure.rs:84:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
|
|
@ -75,13 +90,18 @@ LL | Either::One(_t)
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &e {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:43:15
|
||||
--> $DIR/move-into-closure.rs:90:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
|
|
@ -98,13 +118,18 @@ LL | Either::One(_t) => (),
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &e {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:51:25
|
||||
--> $DIR/move-into-closure.rs:98:25
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
|
|
@ -118,13 +143,18 @@ LL | let X(mut _t) = x;
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let X(mut _t) = &x;
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:54:38
|
||||
--> $DIR/move-into-closure.rs:101:38
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -138,13 +168,18 @@ LL | if let Either::One(mut _t) = em { }
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | if let Either::One(mut _t) = &em { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:57:41
|
||||
--> $DIR/move-into-closure.rs:104:41
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -158,13 +193,18 @@ LL | while let Either::One(mut _t) = em { }
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | while let Either::One(mut _t) = &em { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:60:15
|
||||
--> $DIR/move-into-closure.rs:107:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -181,13 +221,18 @@ LL | Either::One(mut _t)
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:66:15
|
||||
--> $DIR/move-into-closure.rs:113:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -204,13 +249,540 @@ LL | Either::One(mut _t) => (),
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:13:18
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:132:21
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
LL | let X(_t) = x;
|
||||
| -- ^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let X(_t) = &x;
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:135:34
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | if let Either::One(_t) = e { }
|
||||
| -- ^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | if let Either::One(_t) = &e { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:138:37
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | while let Either::One(_t) = e { }
|
||||
| -- ^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | while let Either::One(_t) = &e { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:141:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | match e {
|
||||
| ^
|
||||
...
|
||||
LL | Either::One(_t)
|
||||
| --
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &e {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:147:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | match e {
|
||||
| ^
|
||||
...
|
||||
LL | Either::One(_t) => (),
|
||||
| --
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &e {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:155:25
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | let X(mut _t) = x;
|
||||
| ------ ^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let X(mut _t) = &x;
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:158:38
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | if let Either::One(mut _t) = em { }
|
||||
| ------ ^^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | if let Either::One(mut _t) = &em { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:161:41
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | while let Either::One(mut _t) = em { }
|
||||
| ------ ^^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | while let Either::One(mut _t) = &em { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:164:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | match em {
|
||||
| ^^
|
||||
...
|
||||
LL | Either::One(mut _t)
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:170:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | <() as T>::consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | match em {
|
||||
| ^^
|
||||
...
|
||||
LL | Either::One(mut _t) => (),
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:39:22
|
||||
|
|
||||
LL | fn consume_fn<F: Fn()>(_f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:189:21
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
LL | let X(_t) = x;
|
||||
| -- ^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let X(_t) = &x;
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:192:34
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | if let Either::One(_t) = e { }
|
||||
| -- ^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | if let Either::One(_t) = &e { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:195:37
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | while let Either::One(_t) = e { }
|
||||
| -- ^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | while let Either::One(_t) = &e { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:198:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | match e {
|
||||
| ^
|
||||
...
|
||||
LL | Either::One(_t)
|
||||
| --
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &e {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:204:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | match e {
|
||||
| ^
|
||||
...
|
||||
LL | Either::One(_t) => (),
|
||||
| --
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &e {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:212:25
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | let X(mut _t) = x;
|
||||
| ------ ^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let X(mut _t) = &x;
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:215:38
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | if let Either::One(mut _t) = em { }
|
||||
| ------ ^^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | if let Either::One(mut _t) = &em { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:218:41
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | while let Either::One(mut _t) = em { }
|
||||
| ------ ^^
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | while let Either::One(mut _t) = &em { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:221:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | match em {
|
||||
| ^^
|
||||
...
|
||||
LL | Either::One(mut _t)
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure
|
||||
--> $DIR/move-into-closure.rs:227:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
...
|
||||
LL | ().method_consume_fn(|| {
|
||||
| -- captured by this `Fn` closure
|
||||
...
|
||||
LL | match em {
|
||||
| ^^
|
||||
...
|
||||
LL | Either::One(mut _t) => (),
|
||||
| ------
|
||||
| |
|
||||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:50:29
|
||||
|
|
||||
LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { }
|
||||
| ^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:85:21
|
||||
--> $DIR/move-into-closure.rs:246:21
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
|
|
@ -223,13 +795,18 @@ LL | let X(_t) = x;
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let X(_t) = &x;
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:88:34
|
||||
--> $DIR/move-into-closure.rs:249:34
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
|
|
@ -243,13 +820,18 @@ LL | if let Either::One(_t) = e { }
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | if let Either::One(_t) = &e { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:91:37
|
||||
--> $DIR/move-into-closure.rs:252:37
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
|
|
@ -263,13 +845,18 @@ LL | while let Either::One(_t) = e { }
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | while let Either::One(_t) = &e { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:94:15
|
||||
--> $DIR/move-into-closure.rs:255:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
|
|
@ -286,13 +873,18 @@ LL | Either::One(_t)
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &e {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:100:15
|
||||
--> $DIR/move-into-closure.rs:261:15
|
||||
|
|
||||
LL | let e = Either::One(X(Y));
|
||||
| - captured outer variable
|
||||
|
|
@ -309,13 +901,18 @@ LL | Either::One(_t) => (),
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &e {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:108:25
|
||||
--> $DIR/move-into-closure.rs:269:25
|
||||
|
|
||||
LL | let x = X(Y);
|
||||
| - captured outer variable
|
||||
|
|
@ -329,13 +926,18 @@ LL | let X(mut _t) = x;
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let X(mut _t) = &x;
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:111:38
|
||||
--> $DIR/move-into-closure.rs:272:38
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -349,13 +951,18 @@ LL | if let Either::One(mut _t) = em { }
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | if let Either::One(mut _t) = &em { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:114:41
|
||||
--> $DIR/move-into-closure.rs:275:41
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -369,13 +976,18 @@ LL | while let Either::One(mut _t) = em { }
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | while let Either::One(mut _t) = &em { }
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:117:15
|
||||
--> $DIR/move-into-closure.rs:278:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -392,13 +1004,18 @@ LL | Either::One(mut _t)
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:123:15
|
||||
--> $DIR/move-into-closure.rs:284:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -415,13 +1032,18 @@ LL | Either::One(mut _t) => (),
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/move-into-closure.rs:130:15
|
||||
--> $DIR/move-into-closure.rs:291:15
|
||||
|
|
||||
LL | let mut em = Either::One(X(Y));
|
||||
| ------ captured outer variable
|
||||
|
|
@ -438,11 +1060,16 @@ LL | Either::One(mut _t) => (),
|
|||
| data moved here
|
||||
| move occurs because `_t` has type `X`, which does not implement the `Copy` trait
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/move-into-closure.rs:25:21
|
||||
|
|
||||
LL | fn consume_fnmut<F: FnMut()>(_f: F) { }
|
||||
| ^^^^^^^
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | match &em {
|
||||
| +
|
||||
|
||||
error: aborting due to 21 previous errors
|
||||
error: aborting due to 41 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0507`.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ LL |
|
|||
LL | var = Some(NotCopyable);
|
||||
| --- variable moved due to use in closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/option-content-move2.rs:5:12
|
||||
|
|
||||
LL | fn func<F: FnMut() -> H, H: FnMut()>(_: F) {}
|
||||
| ^^^^^^^^^^^^
|
||||
note: if `NotCopyable` implemented `Clone`, you could clone the value
|
||||
--> $DIR/option-content-move2.rs:1:1
|
||||
|
|
||||
|
|
@ -38,6 +43,12 @@ LL | move || {
|
|||
LL |
|
||||
LL | var = Some(NotCopyableButCloneable);
|
||||
| --- variable moved due to use in closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/option-content-move2.rs:5:12
|
||||
|
|
||||
LL | fn func<F: FnMut() -> H, H: FnMut()>(_: F) {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ LL | move || {
|
|||
LL | let x = var;
|
||||
| ^^^ move occurs because `var` has type `NotCopyable`, which does not implement the `Copy` trait
|
||||
|
|
||||
= help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
note: if `NotCopyable` implemented `Clone`, you could clone the value
|
||||
--> $DIR/option-content-move3.rs:2:1
|
||||
|
|
||||
|
|
@ -37,6 +38,11 @@ LL | move || {
|
|||
LL | let x = var;
|
||||
| --- variable moved due to use in closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/option-content-move3.rs:6:12
|
||||
|
|
||||
LL | fn func<F: FnMut() -> H, H: FnMut()>(_: F) {}
|
||||
| ^^^^^^^^^^^^
|
||||
note: if `NotCopyable` implemented `Clone`, you could clone the value
|
||||
--> $DIR/option-content-move3.rs:2:1
|
||||
|
|
||||
|
|
@ -57,6 +63,7 @@ LL | move || {
|
|||
LL | let x = var;
|
||||
| ^^^ move occurs because `var` has type `NotCopyableButCloneable`, which does not implement the `Copy` trait
|
||||
|
|
||||
= help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
help: consider borrowing here
|
||||
|
|
||||
LL | let x = &var;
|
||||
|
|
@ -77,6 +84,11 @@ LL | move || {
|
|||
LL | let x = var;
|
||||
| --- variable moved due to use in closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/option-content-move3.rs:6:12
|
||||
|
|
||||
LL | fn func<F: FnMut() -> H, H: FnMut()>(_: F) {}
|
||||
| ^^^^^^^^^^^^
|
||||
help: consider cloning the value before moving it into the closure
|
||||
|
|
||||
LL ~ {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ LL | let f = to_fn(|| drop(x));
|
|||
| |
|
||||
| captured by this `Fn` closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/unboxed-closure-illegal-move.rs:7:33
|
||||
|
|
||||
LL | fn to_fn<A:std::marker::Tuple,F:Fn<A>>(f: F) -> F { f }
|
||||
| ^^^^^
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | let f = to_fn(|| drop(x.clone()));
|
||||
|
|
@ -27,6 +32,11 @@ LL | let f = to_fn_mut(|| drop(x));
|
|||
| |
|
||||
| captured by this `FnMut` closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/unboxed-closure-illegal-move.rs:8:37
|
||||
|
|
||||
LL | fn to_fn_mut<A:std::marker::Tuple,F:FnMut<A>>(f: F) -> F { f }
|
||||
| ^^^^^^^^
|
||||
help: consider cloning the value if the performance cost is acceptable
|
||||
|
|
||||
LL | let f = to_fn_mut(|| drop(x.clone()));
|
||||
|
|
@ -43,6 +53,12 @@ LL | let f = to_fn(move || drop(x));
|
|||
| ------- ^ `x` is moved here
|
||||
| |
|
||||
| captured by this `Fn` closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/unboxed-closure-illegal-move.rs:7:33
|
||||
|
|
||||
LL | fn to_fn<A:std::marker::Tuple,F:Fn<A>>(f: F) -> F { f }
|
||||
| ^^^^^
|
||||
|
||||
error[E0507]: cannot move out of `x`, a captured variable in an `FnMut` closure
|
||||
--> $DIR/unboxed-closure-illegal-move.rs:32:40
|
||||
|
|
@ -55,6 +71,12 @@ LL | let f = to_fn_mut(move || drop(x));
|
|||
| ------- ^ `x` is moved here
|
||||
| |
|
||||
| captured by this `FnMut` closure
|
||||
|
|
||||
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
|
||||
--> $DIR/unboxed-closure-illegal-move.rs:8:37
|
||||
|
|
||||
LL | fn to_fn_mut<A:std::marker::Tuple,F:FnMut<A>>(f: F) -> F { f }
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue