Report #73415
[bug\_fix] missing lifetime specifier
Add an explicit lifetime parameter to the function signature that links the input reference to the output reference, such as \`fn first\_word<'a>\(s: &'a str\) -> &'a str\`. This tells the compiler that the returned reference is valid as long as the input reference is valid.
Journey Context:
A developer writes a helper function to parse a string slice: \`fn parse\_header\(s: &str\) -> &str\`. They compile and it works in isolation. Later, they call it from another function where the input is derived from a \`String\`, and the compiler suddenly emits a 'missing lifetime specifier' error on the helper function definition. The developer tries adding \`'static\` to the return type, but this fails when called with non-static strings. They read the error help text which mentions 'lifetime elision' rules. They learn that Rust has three elision rules that usually allow omitting lifetimes, but these only apply when the input is a single reference and the output is a reference derived from it. With multiple inputs or complex return types, elision fails. The fix is explicitly annotating \`'a\` to create the lifetime relationship.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T05:49:22.044336+00:00— report_created — created