Closed
Description
See this example, which fails to compile:
fn foo<F>(f: F)
where F: FnOnce()
{
}
fn main() {
let x = Some(vec![1, 2, 3]);
foo(|| {
match x {
Some(y) => { }
None => { }
}
});
}
Error:
<anon>:9:15: 9:16 error: cannot move out of captured outer variable in an `FnOnce` closure
<anon>:9 match x {
^
<anon>:10:18: 10:19 note: attempting to move value to here
<anon>:10 Some(y) => { }
^
<anon>:10:18: 10:19 help: to prevent the move, use `ref y` or `ref mut y` to capture value by reference
error: aborting due to previous error
playpen: application terminated with error code 101