NLL: Better Diagnostic When "Later" means "A Future Loop Iteration" by davidtwco · Pull Request #52948 · rust-lang/rust (original) (raw)

let mut acc = Counter{map: HashMap::new()};
for line in vec!["123456789".to_string(), "12345678".to_string()] {
let v: Vec<&str> = line.split_whitespace().collect();
//~^ ERROR `line` does not live long enough
println!("accumulator before add_assign {:?}", acc.map);
let mut map = HashMap::new();
for str_ref in v {
let e = map.entry(str_ref);
println!("entry: {:?}", e);
let count = e.or_insert(0);
*count += 1;
}
let cnt2 = Counter{map};
acc += cnt2;
println!("accumulator after add_assign {:?}", acc.map);
// line gets dropped here but references are kept in acc.map
}