Rust: error[E0106]: missing lifetime specifier — this function's return type contains a borrowed value, but the signature does not say which one of `x`'s 2 lifetimes it is borrowed from
The compiler can't infer which input reference the returned/stored reference is tied to.
error[E0106]: missing lifetime specifiermissing lifetime specifierexpected named lifetime parameterthis function's return type contains a borrowed value, but the signature does not say which one ofhelp: consider introducing a named lifetime parameter Meaning
Add lifetime parameters: fn longest<'a>(x: &'a str, y: &'a str) -> &'a str, or return an owned type (String). Structs holding references need struct S<'a> { s: &'a str }. With one input reference elision works; with several or none it doesn't.
Common causes
- Function returns a reference with 2+ reference params
- Struct field with
&Tand no lifetime implblocks missing<'a>- Returning a reference to a local
- Trait objects needing
+ 'a
⚡ Quick fix
- Add
<'a>and tie inputs/outputs - Return owned data (
String,Vec) - Use
'staticonly for truly static data
Detailed fix by platform
Rust
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { if x.len() > y.len() { x } else { y } }
How to diagnose
- Params — How many refs?
- Return — Borrowed from which?
- Alternative — Owned?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Blocking waiting for file lock on package cache / build directory Cargo: Blocking waiting for file lock on package cache / on build directory
- cargo: failed to get from registry (spurious network error) Cargo: warning: spurious network error (2 tries remaining): [35] SSL connect error / error: failed to download from `https://index.crates.io/...`
- cargo: failed to select a version for the requirement Cargo: error: failed to select a version for the requirement `serde = "^2.0"` — candidate versions found which didn't match: 1.0.197
Most viewed in Rust
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026