]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/issue-95079-missing-move-in-nested-closure.stderr
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / issue-95079-missing-move-in-nested-closure.stderr
1 error: captured variable cannot escape `FnMut` closure body
2   --> $DIR/issue-95079-missing-move-in-nested-closure.rs:3:29
3    |
4 LL | fn foo1(s: &str) -> impl Iterator<Item = String> + '_ {
5    |         - variable defined here
6 LL |     None.into_iter()
7 LL |         .flat_map(move |()| s.chars().map(|c| format!("{}{}", c, s)))
8    |                           - -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9    |                           | |
10    |                           | returns a reference to a captured variable which escapes the closure body
11    |                           | variable captured here
12    |                           inferred to be a `FnMut` closure
13    |
14    = note: `FnMut` closures only have access to their captured variables while they are executing...
15    = note: ...therefore, they cannot allow references to captured variables to escape
16 help: consider adding 'move' keyword before the nested closure
17    |
18 LL |         .flat_map(move |()| s.chars().map(move |c| format!("{}{}", c, s)))
19    |                                           ++++
20
21 error: lifetime may not live long enough
22   --> $DIR/issue-95079-missing-move-in-nested-closure.rs:9:15
23    |
24 LL |     move |()| s.chars().map(|c| format!("{}{}", c, s))
25    |     --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
26    |     |       |
27    |     |       return type of closure `Map<Chars<'_>, [closure@$DIR/issue-95079-missing-move-in-nested-closure.rs:9:29: 9:32]>` contains a lifetime `'2`
28    |     lifetime `'1` represents this closure's body
29    |
30    = note: closure implements `Fn`, so references to captured variables can't escape the closure
31 help: consider adding 'move' keyword before the nested closure
32    |
33 LL |     move |()| s.chars().map(move |c| format!("{}{}", c, s))
34    |                             ++++
35
36 error: aborting due to 2 previous errors
37