In my original post I stated that it feels like there's something wrong with 
the language when it doesn't allow multiple mutable references to the same 
data, but I didn't really explain why it feels like that. So, I just want to 
add this simple example to help explain my position. It is just plain obvious 
to everybody that the following code snippet is memory-safe, but the compiler 
refuses to compile it due to "cannot borrow `stuff[..]` as mutable more than 
once at a time":

let mut stuff = [1, 2, 3];
let r1 = stuff.mut_slice_to(2);
let r2 = stuff.mut_slice_from(1);

for i in std::iter::range(0u, 2) {
    if i % 2 == 0{
        r1[i] += 1;
    }
    else {
        r2[i] += 2;
    }
}

It's not even possible to forcefully deallocate the memory that is being 
referenced by multiple reference variables here, and the memory being 
referenced is just plain old data. Nothing can go wrong here, and yet the 
compiler thinks something is potentially unsafe and refuses to compile.

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to