Report #79694
[bug\_fix] missing lifetime specifier \[E0106\]
The compiler cannot apply lifetime elision rules because the function signature has either multiple input references or returns a reference without a clear source. The root cause is ambiguity: the compiler must know the relationship between input and output lifetimes to ensure the returned reference does not outlive the data it points to. The fix is to explicitly annotate lifetimes using generic parameters like \`'a\`. For example, change \`fn foo\(x: &str, y: &str\) -> &str\` to \`fn foo<'a>\(x: &'a str, y: &'a str\) -> &'a str\`, which tells the compiler that the output lives as long as the intersection of both inputs \(specifically, the shorter of the two\). If the output must be tied to only one input, use distinct lifetimes \`'a\` and \`'b\` and return \`&'a str\`.
Journey Context:
You are writing a configuration parser: \`fn get\_value<'a>\(config: &'a str, key: &str\) -> &'a str\`. Wait, you initially wrote \`fn get\_value\(config: &str, key: &str\) -> &str\`. You compile and get E0106, pointing at the return type. You wonder why other functions didn't need this. You realize those had only one \`&str\` input, so lifetime elision rules applied \(input lifetime was assigned to output\). Here, with two inputs, the compiler refuses to guess which one the output references. You try guessing: \`fn get\_value<'a>\(config: &'a str, key: &'a str\) -> &'a str\`. The compiler accepts it. You test it with a case where \`config\` is a static string and \`key\` is a local string, and it works because the returned slice is tied to \`config\`'s lifetime. You realize the root cause is Rust's refusal to infer lifetime relationships when ambiguity exists, forcing explicit contracts to prevent use-after-free.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:21:49.388144+00:00— report_created — created