Closed
Description
I tried this code:
fn main() {
struct Xd;
impl Xd {
fn x(&mut self, y: &str) {println!("{}", y)}
}
let mut xd = Xd;
xd.x(match "x" {
"x" => {
xd.x("x");
"x"
},
_ => "y"
})
}
I expected to see this happen: print x twice
Instead, this happened:
Compiling playground v0.0.1 (/playground)
error[E0499]: cannot borrow `xd` as mutable more than once at a time
--> src/main.rs:9:13
|
7 | xd.x(match "x" {
| -- - first borrow later used by call
| |
| first mutable borrow occurs here
8 | "x" => {
9 | xd.x("x");
| ^^ second mutable borrow occurs here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0499`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Meta
rustc --version --verbose
:
1.54.0