-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Disambiguate associated function calls #19995
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
Rust: Disambiguate associated function calls #19995
Conversation
fc8ff54
to
0aaedf5
Compare
c2ad6f9
to
0ef372f
Compare
a36613d
to
67ecb66
Compare
7fa76b7
to
604fda8
Compare
604fda8
to
c7d20eb
Compare
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.
Seems plausible. I understand that the new missing results are left for follow up, right?
Yes. |
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.
Changes to tests and test inconsistencies look great! Changes on DCA look fine as well. I haven't checked the QL in detail but the intent sounds very reasonable.
This PR implements type-based disambiguation of calls to associated functions.
Before this PR, whenever we saw a call to an associated function like
we would resolve
bar
to whatever our path resolution logic did. However, this could result in two kinds of ambiguities that this PR resolves.Overlapping trait implementations
In a call like
i64::my_from(73i64)
, path resolution resolvesmy_from
to both implementations, and type information about the argument73i64
is required to disambiguate. This is an extension of #19749.Calls to trait functions
Using the example above, in a call like
MyFrom::my_from(73i64)
, path resolution resolvesmy_from
to the trait function. We then need consider all possible implementations ofmy_from
, and pick the one(s) where the argument types match the parameter types.Another typical instance of this is calls to
Default::default()
, where we have no arguments to determine the relevant call target. Instead, we need to use type information about the context in which the call occurs, e.g. inlet x : i64 = Default::default()
we know that the return type should bei64
.DCA looks fine, though the percentage of resolvable calls drops from 59.6 % to 56.5 %, which is more than I had anticipated. Given that this PR unblocks other work, we can investigate the missing call targets follow-up.