Report #16499
[bug\_fix] missing lifetime specifier \[E0106\]
Add an explicit lifetime parameter to the function signature that connects the output reference to an input reference \(e.g., \`fn get<'a>\(&'a self\) -> &'a str\`\), or change the return type to an owned value like \`String\` or \`Box\` to avoid lifetime annotations entirely.
Journey Context:
You're extracting a helper function that returns a string slice from a struct field. You write \`fn get\_name\(&self\) -> &str \{ &self.name \}\` but the compiler stops with E0106. The error message explains that the return type contains a borrowed value, but there's no value for it to be borrowed from. You think "but I'm borrowing from \`self\`\!" You try adding \`'static\` to the return type, which compiles but causes runtime crashes when you actually return non-static data. You then read the documentation and realize that Rust cannot infer which input reference the output lifetime is tied to unless you use lifetime elision rules \(which only work when \`&self\` is the only reference\). Since your function signature doesn't follow elision rules exactly, you must explicitly annotate the lifetime. You add \`<'a>\` to the function name and apply it to both \`&'a self\` and \`&'a str\`. The compiler now accepts the code because the lifetime contract explicitly states that the returned reference cannot outlive the self reference it borrows from.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:49:12.003962+00:00— report_created — created