See the following code:
enum TestEnum {
Item(i32),
}
fn test(_: &mut i32) {
}
fn main() {
let mut x = TestEnum::Item(10);
match x {
TestEnum::Item(ref mut x) => {
test(&mut x);
}
}
}
The compiler raises error and suggests that:
error: cannot borrow immutable local variable `x` as mutable
--> <anon>:12:23
|
11 | TestEnum::Item(ref mut x) => {
| --------- use `ref mut mut x` here to make mutable
12 | test(&mut x);
| ^ cannot borrow mutably
which doesn't make sense, because ref mut mut is invalid.
The correct code here is actually using test(x) directly as x itself is already a mutable reference there.