fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1error: captured variable cannot escape `FnMut` closure body 2 --> $DIR/issue-95079-missing-move-in-nested-closure.rs:5:29 3 | 4LL | fn foo1(s: &str) -> impl Iterator<Item = String> + '_ { 5 | - variable defined here 6LL | None.into_iter() 7LL | .flat_map(move |()| s.chars().map(|c| format!("{}{}", c, s))) 8 | - -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9 | | | 10 | | returns a closure that contains a reference to a captured variable, which then 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 16help: consider adding 'move' keyword before the nested closure 17 | 18LL | .flat_map(move |()| s.chars().map(move |c| format!("{}{}", c, s))) 19 | ++++ 20 21error: lifetime may not live long enough 22 --> $DIR/issue-95079-missing-move-in-nested-closure.rs:11:15 23 | 24LL | 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:11:29: 11: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 31help: consider adding 'move' keyword before the nested closure 32 | 33LL | move |()| s.chars().map(move |c| format!("{}{}", c, s)) 34 | ++++ 35 36error: captured variable cannot escape `FnMut` closure body 37 --> $DIR/issue-95079-missing-move-in-nested-closure.rs:21:9 38 | 39LL | bar: &'a X, 40 | --- variable defined here 41LL | ) -> impl Iterator<Item = ()> + 'a { 42LL | Some(()).iter().flat_map(move |()| { 43 | - inferred to be a `FnMut` closure 44LL | Some(()).iter().map(|()| { bar; }) 45 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^---^^^^ 46 | | | 47 | | variable captured here 48 | returns a closure that contains a reference to a captured variable, which then escapes the closure body 49 | 50 = note: `FnMut` closures only have access to their captured variables while they are executing... 51 = note: ...therefore, they cannot allow references to captured variables to escape 52help: consider adding 'move' keyword before the nested closure 53 | 54LL | Some(()).iter().map(move |()| { bar; }) 55 | ++++ 56 57error: aborting due to 3 previous errors 58