>This rules out a vast majority of fundamental algorithms.
To be more precise, in Rust:
- '&mut T' (a mutable reference to T) can never alias.
- '(asterix) mut T' (a mutable pointer to T) can alias.
The advantage is that you can write most production code with a mix of '&T' and '&mut T', which allows the compiler to assume no mutable aliases anywhere. But if you're building a doubly-linked list, then you can explicitly choose '(asterix) mut T'. (For other options, see https://rust-unofficial.github.io/too-many-lists/.)
In practice, it depends a lot on the code you're writing. I've written tens of thousands of lines of production Rust without needing shared mutability. But if I were writing a traditional game or GUI toolkit, then I might miss shared mutability a lot more.
How does the rust compiler know if two references passed in from calling code can alias or not? (I.e., what if I get the type annotations wrong?).
In general, determining if two pointers can alias is equivalent to the halting problem.
The default C way is “assume aliasing unless you can prove otherwise”. This seems safer and like less work to me.
(The C default you refer to is at the compiler internals level. The Rust alias prevention we’re talking about is at the language level. C compilers will try to avoid generating code that will behave incorrectly in the presence of aliasing, but do nothing to prevent aliasing and the possible logic and thread safety issues caused by aliasing. Rust makes almost all of these cases disappear for the programmer.)
There's another small detail: these two cases are mutually exclusive. You can either have one &mut reference, or as many & references as you want. This means that code receiving a & reference can be sure the object won't change, and that code receiving a &mut reference knows the object can be modified safely since nothing else could be looking at it. (Assuming the object doesn't contain a Cell, the rules are a bit different when a Cell is involved.)
But I'm not proposing to bring that to C (although it seems that generics are slowly creeping in by way of the macro system), I'm just saying that I think the changes proposed in this paper would make the language more complex without really making it easier to write C code 99% of the time.
This rules out a vast majority of fundamental algorithms. Jumping through hoops for getting simple logic working doesn't sound very desirable.