You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
This is working as intended. Method receivers are evaluated before arguments, so the outer function call already borrows xd when the second call is evaluated.
Sorry, I didn't mean to irritate. I just don't understand.
EDIT: So lifetime-wise it's kind of as if struct methods accept closures as arguments and are evaluated in the body of the method? My expectation would be to evaluate arguments and pass into the method. I don't understand why the choice is to evaluate receiver first.
I tried this code:
I expected to see this happen: print x twice
Instead, this happened:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: