Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustborrow checker and NLLSingle-choice MCQ

Why does the following compile under NLL even though `last` holds a shared borrow of `data` that is created inside the loop and `data` is mutated on a later iteration?

let mut data = vec![1, 2, 3]; let mut last = &data[0]; for i in 0..3 { last = &data[i]; println!("{}", last); if i == 1 { // no mutation here } } data.push(4);