Why are explicit lifetimes needed in Rust?
@lebyy▲ 0 net votes
Problem: I was reading the lifetimes chapter of the Rust book, and I came across this example for a named/explicit lifetime: struct Foo<'a> { x: &'a i32, } fn main() { let x; // -+ x goes into scope // | { // | let y = &5; // ---+ It's quite clear to me that the… Fix (from the top answer): The other answers all have salient points ( fjh's concrete example where an explicit lifetime is needed ), but are missing one key thing: why are explicit lifetimes needed when the compiler will tell you you've got them wrong ? This is actually the same question as "why are explicit types needed when the compiler can…