Closed
Description
struct Foo { a: usize }
fn main() {
let mut x = std::rc::Rc::new(Foo { a: 1 });
x.a += 1;
let mut y = &(Foo { a: 1 });
y.a += 1;
}
<anon>:4:5: 4:13 error: cannot assign to immutable field
<anon>:4 x.a += 1;
^~~~~~~~
<anon>:7:5: 7:13 error: cannot assign to immutable field `y.a`
<anon>:7 y.a += 1;
^~~~~~~~
Gives no indication that the field is immutable because it is stored inside an Rc
/&
. These example are somewhat obvious, since the initialiser is directly above, but it's certainly possible to be matching deep inside some data structure and meet this error even though there are mut
s on all the appropriate variables.
The error message could include: "note: this field is immutable because it is being accessed via an &
reference [created by the autoderef of a Rc
]".