Always reborrow mutable reference receiver in methods#14511
Always reborrow mutable reference receiver in methods#14511bors merged 1 commit intorust-lang:masterfrom
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.
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.
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.
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.
That then also mimics what rustc does here
|
@bors r+ |
|
☀️ Test successful - checks-actions |
Dependency of #14470