Closed
Description
The code below compiles and runs as I expect, but when the type annotation is uncommented rustc gives lifetime errors.
I've seen a few similar but not quite the same issues, but I don't think this particular one is already logged (apologies if that's not the case).
use std::vec::Vec;
fn main() {
let nodes = (0..3).collect::<Vec<u32>>();
let references = nodes.iter().map(
|x
// : &u32 // If this line is uncommented I get lifetime problems
| x).collect::<Vec<_>>();
println!("references: {:?}", references);
}
Using the trivial function below instead of a closure compiles without errors.
fn return_reference(x: &u32) -> &u32 {
x
}