-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: Test all generic args for trait when finding matching impl #13475
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
@bors r+ |
I think you should be able to unify the substitutions directly instead of looping manually? That would also take care of consts. |
Also, I think we have some bug report(s) that this fixes as well. |
fix: Test all type args for trait when finding matching impl Addresses #13463 (comment) When finding matching impl for a trait method, we've been testing the unifiability of self type. However, there can be multiple impl of a trait for the same type with different generic arguments for the trait. This patch takes it into account and tests the unifiability of all type arguments for the trait (the first being the self type) thus enables rust-analyzer to find the correct impl even in such cases.
@flodiebold I was pretty sure there's a way to do that! Are you talking about Could someone r-? |
bors r- |
@bors r- |
☀️ Try build successful - checks-actions |
1 similar comment
☀️ Try build successful - checks-actions |
037208e
to
324151d
Compare
324151d
to
6410bb0
Compare
It seems to me we could just make |
6410bb0
to
ed7481a
Compare
|
||
let goal = crate::Goal::all(Interner, wh_goals); | ||
if !table | ||
.unify(trait_ref.substitution.as_slice(Interner), expected_subst.as_slice(Interner)) |
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.
maybe we should just have actual TraitRef
s here, then we could just unify those
db: &dyn HirDatabase, | ||
env: Arc<TraitEnvironment>, | ||
trait_: TraitId, | ||
name: &Name, | ||
fn_subst: Substitution, |
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.
kind of weird to be passing the fn subst, but not the actual fn ID, right? we could just pass the trait subst, and then merge that with the trait_
parameter into a TraitRef
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 weird too. This function is called from hir and I didn't want to let hir manipulate Substitution
s (besides passing them around as-is). It's just my preference so can we just make new Substitution
for the trait out of fn subst in hir layer?
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.
Hmm I think ideally we'd have some nice functions to get the trait ref from a function subst and so on. I think for now either would be fine.
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, that would be useful and an extension method would be good place for it I guess? Will try adding that.
ed7481a
to
67f1d8f
Compare
So I ended up restructuring the related methods.
@flodiebold I'd appreciate if you could take a look again. I think the weirdness is somewhat alleviated and it's more organized than before. |
@bors r+ |
☀️ Test successful - checks-actions |
Addresses #13463 (comment)
When finding matching impl for a trait method, we've been testing the unifiability of self type. However, there can be multiple impl of a trait for the same type with different generic arguments for the trait. This patch takes it into account and tests the unifiability of all type arguments for the trait (the first being the self type) thus enables rust-analyzer to find the correct impl even in such cases.