Why does modifying a mutable reference's value through a raw pointer not violate Rust's aliasing rules?
问题 I don't have a particularly solid understanding of Rust's aliasing rules (and from what I've heard they're not solidly defined), but I'm having trouble understanding what makes this code example in the std::slice documentation okay. I'll repeat it here: let x = &mut [1, 2, 4]; let x_ptr = x.as_mut_ptr(); unsafe { for i in 0..x.len() { *x_ptr.offset(i as isize) += 2; } } assert_eq!(x, &[3, 4, 6]); The problem I see here is that x , being an &mut reference, can be assumed to be unique by the