-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Unify logic in MethodResolution; remove TypeQualifierIsInstantiationOfImplSelf logic
#21366
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
Merged
hvitved
merged 2 commits into
github:main
from
hvitved:rust/type-inference-unify-method-resolution
Feb 26, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,21 +8,31 @@ module Impl { | |
| TPositionalArgumentPosition(int i) { | ||
| i in [0 .. max([any(ParamList l).getNumberOfParams(), any(ArgList l).getNumberOfArgs()]) - 1] | ||
| } or | ||
| TSelfArgumentPosition() | ||
| TSelfArgumentPosition() or | ||
| TTypeQualifierArgumentPosition() | ||
|
|
||
| /** An argument position in a call. */ | ||
| class ArgumentPosition extends TArgumentPosition { | ||
| /** Gets the index of the argument in the call, if this is a positional argument. */ | ||
| int asPosition() { this = TPositionalArgumentPosition(result) } | ||
|
|
||
| /** Holds if this call position is a self argument. */ | ||
| predicate isSelf() { this instanceof TSelfArgumentPosition } | ||
| predicate isSelf() { this = TSelfArgumentPosition() } | ||
|
|
||
| /** | ||
| * Holds if this call position is a type qualifier, that is, not an actual | ||
| * argument, but rather an annotation that is needed to resolve the call target, | ||
| * just like actual arguments may be need to resolve the call target. | ||
|
||
| */ | ||
| predicate isTypeQualifier() { this = TTypeQualifierArgumentPosition() } | ||
|
|
||
| /** Gets a string representation of this argument position. */ | ||
| string toString() { | ||
| result = this.asPosition().toString() | ||
| or | ||
| this.isSelf() and result = "self" | ||
| or | ||
| this.isTypeQualifier() and result = "type qualifier" | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,10 @@ class FunctionPosition extends TFunctionPosition { | |
|
|
||
| ArgumentPosition asArgumentPosition() { this = TArgumentFunctionPosition(result) } | ||
|
|
||
| predicate isTypeQualifier() { this.asArgumentPosition().isTypeQualifier() } | ||
|
|
||
| predicate isSelfOrTypeQualifier() { this.isSelf() or this.isTypeQualifier() } | ||
|
|
||
| predicate isReturn() { this = TReturnFunctionPosition() } | ||
|
|
||
| /** Gets the corresponding position when `f` is invoked via a function call. */ | ||
|
|
@@ -82,9 +86,9 @@ private newtype TAssocFunctionType = | |
| // through `i`. This ensures that `parent` is either a supertrait of `i` or | ||
| // `i` in an `impl` block implementing `parent`. | ||
| (parent = i or BaseTypes::rootTypesSatisfaction(_, TTrait(parent), i, _, _)) and | ||
| // We always include the `self` position, even for non-methods, where it is used | ||
| // We always include the type qualifer position, even for non-methods, where it is used | ||
| // to match type qualifiers against the `impl` or trait type, such as in `Vec::new`. | ||
| (exists(pos.getTypeMention(f)) or pos.isSelf()) | ||
| (exists(pos.getTypeMention(f)) or pos.isTypeQualifier()) | ||
|
||
| } | ||
|
|
||
| bindingset[abs, constraint, tp] | ||
|
|
@@ -116,21 +120,9 @@ Type getAssocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition | |
| else result = getTraitConstraintTypeAt(i, constraint, tp, suffix) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Same as `getAssocFunctionTypeAt`, but also includes types at the `self` position | ||
| * for non-methods. | ||
| */ | ||
| pragma[nomagic] | ||
| Type getAssocFunctionTypeInclNonMethodSelfAt( | ||
| Function f, ImplOrTraitItemNode i, FunctionPosition pos, TypePath path | ||
| ) { | ||
| result = getAssocFunctionTypeAt(f, i, pos, path) | ||
| or | ||
| f = i.getASuccessor(_) and | ||
| not f.hasSelfParam() and | ||
| pos.isSelf() and | ||
| pos.isTypeQualifier() and | ||
| result = resolveImplOrTraitType(i, path) | ||
| } | ||
|
|
||
|
|
@@ -192,7 +184,7 @@ class AssocFunctionType extends MkAssocFunctionType { | |
| Type getTypeAt(TypePath path) { | ||
| exists(Function f, FunctionPosition pos, ImplOrTraitItemNode i, Type t | | ||
| this.appliesTo(f, i, pos) and | ||
| t = getAssocFunctionTypeInclNonMethodSelfAt(f, i, pos, path) | ||
| t = getAssocFunctionTypeAt(f, i, pos, path) | ||
| | | ||
| not t instanceof SelfTypeParameter and | ||
| result = t | ||
|
|
||
Oops, something went wrong.
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.
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.
Grammar in comment: "may be need" should be "may be needed".