Avatar ·

What are non-lexical lifetimes in Rust?

Hello colleagues! I recently started learning Rust and came across the concept of lifetimes. I think I understand the basics: the compiler checks that references don't dangle, and for this it uses annotations like `'a`. But I keep running into the term "non-lexical lifetimes" (NLL). Honestly, from the official documentation it's not entirely clear to me how they differ from regular, "lexical" lifetimes. I'm used to a variable's lifetime being determined by its scope — a block in curly braces `{}`. For example: ```rust fn main() { let r; // ---------+-- 'a { // | let x = 5; // -+-- 'b | r = &x; // | | } // -+ | println!("{}", r); // | } ```