E0106: missing lifetime specifier Rust Origin: Application & API Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: Rust

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 &T and no lifetime
  • impl blocks missing <'a>
  • Returning a reference to a local
  • Trait objects needing + 'a

⚡ Quick fix

  1. Add <'a> and tie inputs/outputs
  2. Return owned data (String, Vec)
  3. Use 'static only for truly static data

Detailed fix by platform

Rust

  1. fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { if x.len() > y.len() { x } else { y } }

How to diagnose

  1. Params — How many refs?
  2. Return — Borrowed from which?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Blocking waiting for file lock on package cache / build directory — Cargo: Blocking waiting for file lock on package cache / on build directory (Rust)Blocking waiting for …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/...` (Rust)cargo: failed to get …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 (Rust)cargo: failed to sele…E0373: closure may outlive the current function — Rust: error[E0373]: closure may outlive the current function, but it borrows `v`, which is owned by the current function (Rust)E0373: closure may ou…E0502 — Rust: error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable (Rust)E0502E0521: borrowed data escapes outside of function — Rust: error[E0521]: borrowed data escapes outside of function — `data` escapes the function body here (tokio::spawn requires 'static) (Rust)E0521: borrowed data …E0597: borrowed value does not live long enough — Rust: error[E0597]: `x` does not live long enough — borrowed value does not live long enough (Rust)E0597: borrowed value…E0716: temporary value dropped while borrowed — Rust: error[E0716]: temporary value dropped while borrowed — creates a temporary value which is freed while still in use (Rust)E0716: temporary valu…E0106: mi…

Explore the map of this error Full error map →

🧠 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.