Why does Rust disallow mutable aliasing?
问题 Rust disallows this kind of code because it is unsafe: fn main() { let mut i = 42; let ref_to_i_1 = unsafe { &mut *(&mut i as *mut i32) }; let ref_to_i_2 = unsafe { &mut *(&mut i as *mut i32) }; *ref_to_i_1 = 1; *ref_to_i_2 = 2; } How can I do do something bad ( e.g. segmentation fault, undefined behavior, etc.) with multiple mutable references to the same thing? The only possible issues I can see come from the lifetime of the data. Here, if i is alive, each mutable reference to it should be