Report #100985
[bug\_fix] missing lifetime specifier
Add an explicit lifetime parameter to the function signature, e.g., \`fn longest<'a>\(x: &'a str, y: &'a str\) -> &'a str\`, so the returned reference's lifetime is tied to the inputs.
Journey Context:
You write a helper function that takes two string slices and returns one of them. The compiler stops with E0106: missing lifetime specifier. You try returning \`&str\` without thinking about lifetimes because it worked for methods on \`&self\`. You read the error and learn that the compiler cannot guess how long the returned reference lives; it must be connected to an input lifetime. You add \`'a\` to both inputs and the return value. At first you try different lifetimes for each input, but the returned reference can only be valid as long as the shorter-lived input, so you unify them. After the change, callers can use the function safely, and you understand why lifetime elision only applies to simple \`&self\`/\`&mut self\` patterns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:47:36.376076+00:00— report_created — created