2022-07-22 11:53:39 -05:00
|
|
|
error: captured variable cannot escape `FnMut` closure body
|
2023-01-07 16:17:00 -06:00
|
|
|
--> $DIR/issue-95079-missing-move-in-nested-closure.rs:5:29
|
2022-07-22 11:53:39 -05:00
|
|
|
|
|
|
|
|
LL | fn foo1(s: &str) -> impl Iterator<Item = String> + '_ {
|
|
|
|
| - variable defined here
|
|
|
|
LL | None.into_iter()
|
|
|
|
LL | .flat_map(move |()| s.chars().map(|c| format!("{}{}", c, s)))
|
|
|
|
| - -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
| | |
|
2023-01-07 16:17:00 -06:00
|
|
|
| | returns a closure that contains a reference to a captured variable, which then escapes the closure body
|
2022-07-22 11:53:39 -05:00
|
|
|
| | variable captured here
|
|
|
|
| inferred to be a `FnMut` closure
|
|
|
|
|
|
|
|
|
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
|
|
|
= note: ...therefore, they cannot allow references to captured variables to escape
|
|
|
|
help: consider adding 'move' keyword before the nested closure
|
|
|
|
|
|
|
|
|
LL | .flat_map(move |()| s.chars().map(move |c| format!("{}{}", c, s)))
|
|
|
|
| ++++
|
|
|
|
|
|
|
|
error: lifetime may not live long enough
|
2023-01-07 16:17:00 -06:00
|
|
|
--> $DIR/issue-95079-missing-move-in-nested-closure.rs:11:15
|
2022-07-22 11:53:39 -05:00
|
|
|
|
|
|
|
|
LL | move |()| s.chars().map(|c| format!("{}{}", c, s))
|
|
|
|
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
|
|
|
|
| | |
|
2023-01-07 16:17:00 -06:00
|
|
|
| | return type of closure `Map<Chars<'_>, [closure@$DIR/issue-95079-missing-move-in-nested-closure.rs:11:29: 11:32]>` contains a lifetime `'2`
|
2022-07-22 11:53:39 -05:00
|
|
|
| lifetime `'1` represents this closure's body
|
|
|
|
|
|
|
|
|
= note: closure implements `Fn`, so references to captured variables can't escape the closure
|
|
|
|
help: consider adding 'move' keyword before the nested closure
|
|
|
|
|
|
|
|
|
LL | move |()| s.chars().map(move |c| format!("{}{}", c, s))
|
|
|
|
| ++++
|
|
|
|
|
2023-01-07 16:17:00 -06:00
|
|
|
error: captured variable cannot escape `FnMut` closure body
|
|
|
|
--> $DIR/issue-95079-missing-move-in-nested-closure.rs:21:9
|
|
|
|
|
|
|
|
|
LL | bar: &'a X,
|
|
|
|
| --- variable defined here
|
|
|
|
LL | ) -> impl Iterator<Item = ()> + 'a {
|
|
|
|
LL | Some(()).iter().flat_map(move |()| {
|
|
|
|
| - inferred to be a `FnMut` closure
|
|
|
|
LL | Some(()).iter().map(|()| { bar; })
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^---^^^^
|
|
|
|
| | |
|
|
|
|
| | variable captured here
|
|
|
|
| returns a closure that contains a reference to a captured variable, which then escapes the closure body
|
|
|
|
|
|
|
|
|
= note: `FnMut` closures only have access to their captured variables while they are executing...
|
|
|
|
= note: ...therefore, they cannot allow references to captured variables to escape
|
|
|
|
help: consider adding 'move' keyword before the nested closure
|
|
|
|
|
|
|
|
|
LL | Some(()).iter().map(move |()| { bar; })
|
|
|
|
| ++++
|
|
|
|
|
|
|
|
error: aborting due to 3 previous errors
|
2022-07-22 11:53:39 -05:00
|
|
|
|