Rust: Disambiguate associated function calls#19995
Merged
hvitved merged 4 commits intogithub:mainfrom Jul 10, 2025
Merged
Conversation
fc8ff54 to
0aaedf5
Compare
c2ad6f9 to
0ef372f
Compare
a36613d to
67ecb66
Compare
7fa76b7 to
604fda8
Compare
604fda8 to
c7d20eb
Compare
redsun82
approved these changes
Jul 10, 2025
Contributor
Author
Yes. |
geoffw0
reviewed
Jul 10, 2025
Contributor
geoffw0
left a comment
There was a problem hiding this comment.
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
barto 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_fromto both implementations, and type information about the argument73i64is 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_fromto 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.