Report #75917
[bug\_fix] missing lifetime specifier \[E0106\]
Add explicit lifetime annotations: \`fn longest<'a>\(x: &'a str, y: &'a str\) -> &'a str\`. The root cause is that when a function has multiple input references and returns a reference, the compiler cannot assume which input's lifetime the output is tied to \(or if it's a new lifetime\), so explicit lifetime parameters are required to express the relationship.
Journey Context:
Developer writes a helper function to compare two strings and return the longer one, taking \`&str\` references to avoid allocation. They write \`fn longest\(x: &str, y: &str\) -> &str\`. The compiler immediately stops with E0106, explaining that the return type contains a borrowed value but the signature doesn't say if it's borrowed from \`x\` or \`y\`. The developer initially tries to return \`&'static str\` but realizes that doesn't work for the input data. They read the error help text which suggests using named lifetime parameters. They add \`<'a>\` to the function and all reference types, tying them to the same lifetime. The code compiles because the borrow checker now understands that the returned reference is valid as long as both inputs are valid.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:01:37.031771+00:00— report_created — created