# 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

**Code:** `E0106: missing lifetime specifier` · **Category:** Rust · **Seen on:** Rust

The compiler can't infer which input reference the returned/stored reference is tied to.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/rust/e0106-missing-lifetime-specifier)
