Closed
Description
Given code like:
fn foo(a: &mut Bar) {}
fn baz(b: &mut Bar) {
foo(&mut b)
}
rustc
correctly points out that you "cannot borrow immutable argument b
as mutable", and offers a fix of:
fn baz(b: &mut Bar) {
- consider changing this to `mut b`
A better fix, in this case (and many others where I make this error), is to simply drop the &mut
:
fn baz(b: &mut Bar) {
foo(b)
}
I hit this error quite frequently, and remember finding the addition and removal of &mut
until the compiler shut up about syntactic noise that I didn't care about (etc. etc.) pretty confusing; especially around Write
.
Full code as a playground: https://play.rust-lang.org/?gist=9b69414d92287359bd6f1b91a53b254a&version=stable
If anyone can think of a better way to phrase the subject of this issue, please do change it.