Description
I would like to implement the solution for Dan's Bug based on immutability that I proposed earlier. I have updated the page to describe my latest version, which does not include the separate class of "assignable types". Instead, we make use of #1273 (explicitly mutable local variables) and the work on regions to ensure that the type system can always distinguish immutable and mutable state.
The main change is to prohibit dangerous patterns (as described in the proposal) from being matched against potentially mutable state. An additional change would be to introduce copy
patterns, which cause the value being matched to be copied out into a temporary, immutable space (this is more of a convenience than a requirement).
Even if we scale back regions, I think that this approach is simpler and less error-prone than the existing one. It does however require distinguishing "const" references from "immutable" references (right now, both are &&
). With region pointers, this is done for us, as we have &T
, &const T
, and &mut T
.