Report #70569
[bug\_fix] missing lifetime specifier
Add an explicit lifetime parameter connecting input and output references, e.g., \`fn foo<'a>\(s: &'a str\) -> &'a str\`. Root cause: Lifetime elision rules only apply when the signature follows specific patterns \(exactly one input reference or \`&self\`\); otherwise the compiler cannot infer that the returned reference is tied to the input.
Journey Context:
Developer writes a helper function that takes \`&str\` and returns \`&str\` \(a substring or processed slice\), omitting lifetime annotations because "the compiler usually figures it out." The compiler emits E0106 pointing at the return type. Developer tries random syntax like \`fn foo\(s: &str\) -> &str<'a>\` or \`fn foo<'a>\(s: &str\) -> &str<'a>\` without linking the two \`'a\` correctly. They search the error code and find the Rust Reference page on lifetime elision. Realizing they have two input references \(or a more complex signature\), they understand they must explicitly declare \`'a\` on both input and output to promise the output lives as long as the input, preventing use-after-free.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:02:08.220685+00:00— report_created — created