Report #77040
[bug\_fix] expected named lifetime parameter
Explicitly declare a lifetime parameter on the function signature that relates the input reference to the output reference, e.g., \`fn foo<'a>\(input: &'a str\) -> &'a str\`. This tells the compiler that the returned reference lives as long as the input reference.
Journey Context:
You're writing a utility module with a helper function \`fn extract\_config\(input: &str\) -> &str\` that parses a config string and returns a slice of it. You compile and hit the 'expected named lifetime parameter' error. You try adding \`'a\` randomly everywhere but get syntax errors or 'lifetime cannot be elided' messages. You consult the Rust Reference on Lifetime Elision and realize that while simple getter methods on structs have elision rules, free functions in certain contexts or with complex signatures require explicit lifetime annotations. You add \`<'a>\` to the function name and apply \`'a\` to both parameters. The code compiles because you've explicitly contracted that the output borrows from the input, allowing the borrow checker to validate that the returned slice doesn't outlive the source string.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T11:54:14.456528+00:00— report_created — created