Open
Description
This code (play):
struct X;
impl X {
fn mutate(&mut self) {}
}
fn main() {
let term = Some(X);
let term = match &term {
Some(term) => &mut term,
None => term.as_ref().unwrap(),
};
term.mutate();
}
Produces these errors:
error[E0596]: cannot borrow `term` as mutable, as it is not declared as mutable
--> src/main.rs:9:23
|
9 | Some(term) => &mut term,
| ^^^^^^^^^
| |
| cannot borrow as mutable
| try removing `&mut` here
error[E0596]: cannot borrow `*term` as mutable, as it is behind a `&` reference
--> src/main.rs:12:5
|
9 | Some(term) => &mut term,
| --------- help: consider changing this to be a mutable reference: `&mut mut term`
...
12 | term.mutate();
| ^^^^ `term` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error: aborting due to 2 previous errors
Note that the second error suggests changing &mut term
to &mut mut term
, which obviously won't fix the issue.