Closed
Description
This snippet does not compile with the following error:
pub fn main() {
|i: u32| { || i };
}
error[E0597]: `i` does not live long enough
--> src/main.rs:2:19
|
2 | |i: u32| { || i };
| -- ^ - borrowed value dropped before borrower
| | |
| | borrowed value does not live long enough
| capture occurs here
|
= note: values in a scope are dropped in the opposite order they are created
But adding a move
fixes it:
pub fn main() {
|i: u32| { move || i };
}
I believe the compiler tries to suggest move
where appropriate, and it seems that this case has been missed.