-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Inconsistent auto-reborrowing behavior of generic functions #65279
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
Comments
I think this question is better suited for the rust user forum at https://users.rust-lang.org I can't see, that this is a bug, but hey: prove me wrong ;) |
@hellow554 Maybe you're right in that this is not a bug, but anyway I think there's some space for improvements. The current behavior seems suboptimal to me, and maybe we can make it behave more consistently? |
Now I think this is related to #35919. In Here's another interesting example, which can also be confusing for new comers: struct Struct<T> {
s: T,
t: T,
}
let x = &mut 0i32;
let y = &mut 1i32;
let u = Struct{ s: x, t: y }; // x is moved, y is reborrowed
let v = Struct{ t: y, s: x }; // y is moved, x is reborrowed Maybe we should add some clarification to our doc? |
Unfortunately I don't think this is really actionable -- this is certainly a subtle area of the language but I do not believe we can make any real improvements to documentation here given how "in the weeds" this is. I'm going to close to that effect, especially since #35919 as you mention covers similar ground (so, in some sense, though not a perfect one, this is a close-to-duplicate). |
I understand the explanation but this is really confusing. |
Look at this piece of code:
From the internet, I get the impression that generic functions will not auto-reborrow if the type of parameter cannot be determined to be a mutable reference before instantiation.
It works as expected for
x
:But does auto-reborrow for
y
:Now this is really confusing. What's the exact rules for auto-reborrow? When does it happen, before or after type inference?
The text was updated successfully, but these errors were encountered: