External Publication
Visit Post

Private lifetime inference

Rust Internals [Unofficial] March 16, 2026
Source

redradist:

Closures already do this. |x: &str, y: &str| -> &str { x } infers lifetimes from the body.

Does it?

error: lifetime may not live long enough
 --> src/main.rs:2:34
  |
2 |     |x: &str, y: &str| -> &str { x };
  |         -                 -      ^ returning this value requires that `'1` must outlive `'2`
  |         |                 |
  |         |                 let's call the lifetime of this reference `'2`
  |         let's call the lifetime of this reference `'1`

Playground

Discussion in the ATmosphere

Loading comments...