Closed
Description
fn main() {
let my_text = Some(String::from("my_text"));
let runner = move || {
if let Some(s) = my_text {
println!("Here it is: {}", s);
}
};
runner();
}
This fails to compile on 1.20 (and a few earlier versions that I tried) with:
error[E0507]: cannot move out of captured outer variable in an `Fn` closure
--> src/main.rs:6:26
|
2 | let my_text = Some(String::from("My text"));
| ------- captured outer variable
...
6 | if let Some(s) = my_text {
| - ^^^^^^^ cannot move out of captured outer variable in an `Fn` closure
| |
| hint: to prevent move, use `ref s` or `ref mut s`
But this should be capturing my_text
by move and generating an FnOnce
shouldn't it?
This issue was originally brought up in https://users.rust-lang.org/t/moving-option-into-a-closure-by-binding-it-in-a-pattern-does-not-work-noob-question/12721