3 ms·
Can someone explain to me why it's not possible to have two mutable borrows of a pointer with overlapping lifetimes? Under what circumstances would this be uns
by comex 13y ago
Can someone explain to me why it's not possible to have two mutable borrows of a pointer with overlapping lifetimes? Under what circumstances would this be unsafe in single-threaded code?
- pcwalton 13y agoIterator 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 }