What is NLL Non-Lexical Lifetimes

NLL is Rust's advanced borrow checker that tracks reference lifetimes based on actual usage points rather than syntactic scopes.

NLL (Non-Lexical Lifetimes) is Rust's modern borrow checker that tracks reference validity based on actual usage rather than syntactic scope blocks. It allows references to live only as long as they are actively used, enabling more flexible code patterns without manual lifetime annotations.

fn main() {
    let mut vec = vec![1, 2, 3];
    let first = &vec[0]; // Borrow starts here
    vec.push(4);         // Error in old checker, OK in NLL if first is unused
    println!("{:?}", first); // Borrow ends here
}