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
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=2aa8b97e68b9eba4c1b7c0d3f627c386
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.
This snippet does not compile with the following error:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=2aa8b97e68b9eba4c1b7c0d3f627c386
But adding a
movefixes it:I believe the compiler tries to suggest
movewhere appropriate, and it seems that this case has been missed.