Report #9653
[bug\_fix] lifetime may not live long enough: return value requires that \`input\` is borrowed for \`'static\`
Explicitly annotate the lifetime relationship: \`fn process<'a>\(input: &'a str\) -> &'a str\` to tie the output lifetime to the input.
Journey Context:
Developer writes a function \`extract\` that takes a \`&str\` and returns a slice of it \(e.g., returning the first word\). Initially, with simple signatures, lifetime elision handles it. When they refactor to add a second parameter or use a more complex return path \(e.g., returning either of two input slices based on a condition\), the compiler emits: "lifetime may not live long enough, returned reference does not match any input lifetime". Developer tries randomly sprinkling \`<'a>\` lifetime parameters on the function and return type, but fails to annotate the input parameter: \`fn extract<'a>\(s: &str\) -> &'a str\`. This creates an unconnected lifetime. After reading the error explanation, they realize the \`'a\` must appear on both input and output: \`fn extract<'a>\(s: &'a str\) -> &'a str\`. The fix works because it explicitly constrains the returned reference to be valid only as long as the input reference, satisfying the borrow checker that the data will not outlive its source.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:44:19.285831+00:00— report_created — created