Rust Keyword Generics Progress Report: February 2023
Rust Keyword Generics Progress Report: February 2023
Posted Feb 25, 2023 21:37 UTC (Sat) by NYKevin (subscriber, #129325)In reply to: Rust Keyword Generics Progress Report: February 2023 by xi0n
Parent article: Rust Keyword Generics Progress Report: February 2023
In other words:
* Immutable (shared) references have weaker constraints than mutable (exclusive) references.
* If we implicitly promote a reference to mut, then we impose stronger constraints on your program, which may not be obvious from the call-site.
* Those additional constraints may prove difficult to explain in compile errors, since you may not realize which of your references are mut. The compiler would have to explain how it monomorphized all potentially relevant &?mut annotations, and there might be a lot of them (e.g. "Z is mutable, but you borrow it again over here. Z is mutable because Y is mutable, and Y is mutable because X is mutable, and...").
* More generally, taking &mut everywhere is probably a Bad Idea in the first place (for the same reason that const-correctness is so important in C++).
* Therefore, we don't want to hand you a mutable reference unless you explicitly ask for one.
* The easiest way to accomplish that is to have two methods with different names. Inventing exceptional syntax for an operation that would still require the call-site to manually select a specialization would be pointless.
But I don't work on Rust, so the above is just my best guess.
