3 ms·
> you can't take two mutable references to the same variable in unsafe block, Huh? Creating multiple, unchecked mutable references to the same object is one of
by wahern 7y ago
> you can't take two mutable references to the same variable in unsafe block,
Huh? Creating multiple, unchecked mutable references to the same object is one of the few reasons to even use unsafe. If you get this wrong, Rust's type safety won't save you--any bug effectively undermines the integrity of the remainder of the program. Of course, that doesn't negate the benefits of Rust's type safety, or mean that any program using unsafe is no better than a C or C++ project.
- steveklabnik 7y agoUsually, "mutable reference" refers to &mut T. "mutable pointer" refers to *mut T. Creating aliasing &mut Ts is UB, even in an unsafe block. Sometimes people are not precise about these words, but that's how I read the parent, given they drew the distinction between "mutable reference"s and "raw pointers".
- DominikD 7y agoThank you, this is exactly what I meant.