-
Notifications
You must be signed in to change notification settings - Fork 1.7k
More correct method resolution #2463
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
More correct method resolution #2463
Conversation
| (Ty::Infer(InferTy::IntVar(tv)), other @ ty_app!(TypeCtor::Int(_))) | ||
| (other @ ty_app!(TypeCtor::Int(_)), Ty::Infer(InferTy::IntVar(tv))) | ||
| (Ty::Infer(InferTy::FloatVar(tv)), other @ ty_app!(TypeCtor::Float(_))) | ||
| (other @ ty_app!(TypeCtor::Float(_)), Ty::Infer(InferTy::FloatVar(tv))) => { |
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 is hard to read but I'm not sure how I would clean it up.
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.
Yeah. I feel that type inference is that sort of code where the essential complexity is pretty high, and the only way to make sure that code is maintainable is thorough test coverage.
let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); | ||
let self_ty_with_vars = | ||
Canonical { num_vars: vars.len(), value: &self_ty_with_vars }; | ||
if let Some(substs) = super::infer::unify(self_ty_with_vars, &self_ty.value) |
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.
match might read better here
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's refactored away 🙂
LGTM! |
bors r+ |
2463: More correct method resolution r=flodiebold a=flodiebold This should fix the order in which candidates for method resolution are considered, i.e. `(&Foo).clone()` should now be of type `Foo` instead of `&Foo`. It also checks for inherent candidates that the self type unifies properly with the self type in the impl (i.e. `impl Foo<u32>` methods will only be considered for `Foo<u32>`). To be able to get the correct receiver type to check in the method resolution, I needed the unification logic, so I extracted it to the `unify.rs` module. Should fix #2435. Co-authored-by: Florian Diebold <[email protected]>
Build succeeded
|
This should fix the order in which candidates for method resolution are considered, i.e.
(&Foo).clone()
should now be of typeFoo
instead of&Foo
. It also checks for inherent candidates that the self type unifies properly with the self type in the impl (i.e.impl Foo<u32>
methods will only be considered forFoo<u32>
).To be able to get the correct receiver type to check in the method resolution, I needed the unification logic, so I extracted it to the
unify.rs
module.Should fix #2435.