Report #99160
[bug\_fix] error\[E0106\]: 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\`. The returned reference must share a lifetime with the inputs it borrows from; if only one input is borrowed, tie the output to that input's lifetime.
Journey Context:
You wrote a helper that takes two string slices and returns one of them, expecting it to 'just work' like in garbage-collected languages. The compiler rejects it because Rust cannot infer how long the returned \`&str\` lives relative to the arguments. You try returning \`x\` directly and the error persists. After reading the error, you introduce a generic lifetime \`'a\` and attach it to all references. The key insight is that the lifetime annotation does not change when values are dropped; it is a contract telling the borrow checker that the returned reference is valid only as long as both inputs are valid \(or the specific input you borrow from\). Once the signature is correct, the body compiles unchanged.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:40:02.590035+00:00— report_created — created