struct A;
impl A {
fn foo(&mut self) {}
}
fn main() {
let mut a = A;
let x = &{ &mut a };
x.foo();
}
error[E0389]: cannot borrow data mutably in a `&` reference
--> src/main.rs:9:5
|
9 | x.foo();
| ^ assignment into an immutable reference
You cannot. You have an immutable reference, which means that everything behind the reference is immutable from the point of view of the owner of the reference.
If this wasn't the case, then the whole concept of there only being a single mutable reference to each thing at a time would be trivially breakable.