There is an error in this piece of code:
let a: Vec<_> = (1..10).flat_map(|x| (1..x).map(|_| x)).collect();
The error message:
error[E0597]: `x` does not live long enough
--> src/main.rs:2:57
|
2 | let a: Vec<_> = (1..10).flat_map(|x| (1..x).map(|_| x)).collect();
| --- ^- - borrowed value needs to live until here
| | ||
| | |borrowed value only lives until here
| | borrowed value does not live long enough
| capture occurs here
But why?
Is is a primitive type, i.e. it should be cloned anyway.
What do I understand wrong?