If two mutable references aren’t allowed simultaneously, why are they allowed at all?

According to the documentation, Data races cause undefined behavior and can be difficult to diagnose and fix when you’re trying to track them down at runtime; Rust prevents this problem by refusin...

Stack Overflow

@rust_discussions Somehow I've never seen or thought about the Vec reallocating from under you example.

The application that comes to mind for me is when a function takes both a &mut T and a &T. The &mut T is exclusive, so the compiler can safely do optimizations that assume both parameters reference different values so you can change the &mut T's value without affecting the &T.

@abstractcow @rust_discussions My favorite part of that answer is the comment linking to the C++ std::vector iterator invalidation table, and all the entries are essentially, "Depending on what happens under the hood, this MIGHT invalidate it! 🤷🏻‍♂️"