On 10/9/13 2:31 AM, Bobby Holley wrote:
Ms2ger suggests adding mut_reflector variants of all the methods we
might want to invoke in a mutable fashion. But this kind of
name-mangling seems like a workaround for a problem that the language
should solve, especially given the heavy emphasis on immutability.

Are there any plans for dealing with this problem in the language? If
not, are we designing things wrong in Servo, or should Rust programs
prepend |mut_| to any mutable method that might conceivably have an
immutable variant?

In general prepending `mut_` is the way we've been going.

Solving this in the language would be tricky. We'd have to be careful with C++-style overloading because `&mut self` is coercible to `&self` via reborrowing. Thus `fn reflector(&self) -> &Reflector` would typecheck even if you have an `&mut Self` instance. Perhaps the right thing would be something like mutability variables: `fn reflector<mutability M>(&M self) -> &M Reflector`. Of course then integrating a pointer of unknown mutability introduces borrow check issues similar to those we have with `&const`.

So my answer is: Yes, it's unfortunate, but we'd have to think carefully about how to fix it without breaking the soundness of the language (and while keeping the language easy to reason about).

Patrick

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

Reply via email to