Report #94237
[bug\_fix] missing lifetime specifier \[E0106\]: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from \`x\` or \`y\`
Add explicit lifetime annotations to relate the output lifetime to the inputs. For example, change \`fn longest\(x: &str, y: &str\) -> &str\` to \`fn longest<'a>\(x: &'a str, y: &'a str\) -> &'a str\`. This establishes that the returned reference is valid for as long as both input references are valid.
Journey Context:
The developer writes a helper function that returns a reference: \`fn longest\(x: &str, y: &str\) -> &str\`. With a single parameter, lifetime elision allows this to compile, but with two parameters, the compiler stops with E0106. The developer is confused because they just want to return one of the inputs. They try adding 'static to the return type, which silences the compiler but creates undefined behavior when they return a non-static string slice. They try cloning the strings to return an owned String, which works but feels inefficient. They search the error code and read about "lifetime elision rules" - the compiler's algorithm to infer lifetimes automatically, which only works when there's exactly one input reference or \`&self\`. The epiphany is that with multiple inputs, the compiler cannot know if the output borrows from \`x\`, \`y\`, or both, so the programmer must explicitly annotate the relationship using \`'a\` \(or multiple lifetime parameters if the output only borrows from one specific input\). They add the lifetime parameter and the code compiles, now correctly tracking that the output lifetime is tied to the shorter of the two input lifetimes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:45:54.964264+00:00— report_created — created