Report #97750
[bug\_fix] missing lifetime specifier \[E0106\]
When a function returns a reference \(\`&T\`, \`&str\`, \`&\[T\]\`, etc.\) Rust cannot infer how long that reference lives because input values may have different lifetimes. Annotate the signature with an explicit lifetime parameter, e.g. \`fn first<'a>\(s: &'a str, t: &'a str\) -> &'a str\`, tying the output lifetime to one or more inputs. The returned reference must always derive from owned/ borrowed data that outlives the call.
Journey Context:
You refactor a helper from returning an owned \`String\` to returning \`&str\` for performance, then E0106 appears. You try adding \`&'static str\` because you saw it in examples, but now borrowed local variables fail. You open the compiler error link and the Rust Book lifetime chapter and learn that output lifetimes must be declared relative to input lifetimes. Adding \`<'a>\` and linking both parameters and the return type makes every call site compile and clarifies that the result cannot outlive the shorter of the two inputs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-26T04:38:04.243293+00:00— report_created — created