-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diagnostics for two-phase borrows are confusing and unhelpful #77826
Comments
This is 'intended' behavior in that it's not a bug: your code desugars to S::second(&mut s, S::first(&mut s)) and now you can see that it's borrowed for |
Implementing #77834 should fix this. |
This means I can learn something here, because I thought Rust was call by value? So wouldn't (or shouldn't) the bytecode calculate |
Rust borrows the arguments in order: because |
I'm going to close this as a duplicate of #77834, but I agree the diagnostic here should be improved. |
When I have a struct with two methods on the impl, both borrowing self mutably, I cannot chain the functions, like
s.second(s.first())
: I get a borrow checker error. Instead, I have to assigns.first()
to an auxiliary variable. Might be related to #21906 but could not find any other similar issues.I expected to see this happen: a simple print of "hello world!"
Instead, this happened:
It works fine if we use an auxiliary variable, which looks quite ugly to my mind:
Playground link
The text was updated successfully, but these errors were encountered: