[rust-dev] A better type system

Patrick Walton pcwalton at mozilla.com
Mon Jun 2 08:25:30 PDT 2014


On 6/2/14 12:44 AM, Tommi wrote:
> 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);

I'd like to have a function that splits up a vector in that way. That 
should be doable in the standard library using some unsafe code under 
the hood.

Patrick



More information about the Rust-dev mailing list