3 ms·
Iterator invalidation. If we didn't have that rule you could write this: let mut vector = ~[ 1, 2, 3, 4, 5 ]; for vector.each_mut |x| { //
by pcwalton 13y ago
Iterator invalidation. If we didn't have that rule you could write this:
let mut vector = ~[ 1, 2, 3, 4, 5 ];
for vector.each_mut |x| {
// ^ mutable reference
for 5.times {
vector.pop();
// ~~~~~^ mutable reference
}
println((*x).to_str()); // segfault: invalidated iterator
}