-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Always reborrow mutable reference receiver in methods #14511
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
Conversation
// if `&&T` and `&T` are both applicable, we should prefer `&*&&T` to `&*&T`, so this | ||
// flag exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am somewhat confused by why we need this weird flag at all. This feels very wrong to have. Why did the earlier version not suffice? (where we just introduced a reborrow)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is the problem:
#[test]
fn method_resolution_by_value_before_autoref() {
check_types(
r#"
trait Clone { fn clone(&self) -> Self; }
struct S;
impl Clone for S {}
impl Clone for &S {}
fn test() { (S.clone(), (&S).clone(), (&&S).clone()); }
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (S, S, &S)
"#,
);
}
We should continue for the reborrow only one time, and this flag serve that propose. Without it, we will get (S, S, S)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, now I see what we want to do here. We need to set the autoref
field of the ReceiverAdjustments
first_adjustment
as well as increment the autoderefs
field once for this iterate_method_candidates_by_receiver
call when the receiver_ty
is a reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That then also mimics what rustc does here
@bors r+ |
☀️ Test successful - checks-actions |
Dependency of #14470