-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Improve handling of where clauses in type inference and path resolution #20177
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
Changes from all commits
7660832
b302f3f
0cfb22f
b50a766
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ private import codeql.rust.elements.internal.generated.TypeParam | |||||||||||
*/ | ||||||||||||
module Impl { | ||||||||||||
private import rust | ||||||||||||
private import codeql.rust.internal.PathResolution | ||||||||||||
|
||||||||||||
// the following QLdoc is generated: if you need to edit it, do it in the schema file | ||||||||||||
/** | ||||||||||||
|
@@ -27,6 +28,41 @@ module Impl { | |||||||||||
/** Gets the position of this type parameter. */ | ||||||||||||
int getPosition() { this = any(GenericParamList l).getTypeParam(result) } | ||||||||||||
|
||||||||||||
private TypeBound getTypeBoundAt(int i, int j) { | ||||||||||||
exists(TypeBoundList tbl | result = tbl.getBound(j) | | ||||||||||||
tbl = this.getTypeBoundList() and i = 0 | ||||||||||||
or | ||||||||||||
exists(WherePred wp | | ||||||||||||
wp = this.(TypeParamItemNode).getAWherePred() and | ||||||||||||
tbl = wp.getTypeBoundList() and | ||||||||||||
wp = any(WhereClause wc).getPredicate(i) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic in the second disjunct doesn't guarantee that the
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
) | ||||||||||||
) | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Gets the `index`th type bound of this type parameter, if any. | ||||||||||||
* | ||||||||||||
* This includes type bounds directly on this type parameter and bounds from | ||||||||||||
* any `where` clauses for this type parameter. | ||||||||||||
*/ | ||||||||||||
TypeBound getTypeBound(int index) { | ||||||||||||
result = rank[index + 1](int i, int j | | this.getTypeBoundAt(i, j) order by i, j) | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Gets a type bound of this type parameter. | ||||||||||||
* | ||||||||||||
* This includes type bounds directly on this type parameter and bounds from | ||||||||||||
* any `where` clauses for this type parameter. | ||||||||||||
*/ | ||||||||||||
TypeBound getATypeBound() { | ||||||||||||
// NOTE: This predicate is used in path resolution, so it can not be | ||||||||||||
// defined using `getTypeBound` as that would cause non-monotonic | ||||||||||||
// recursion due to the `rank`. | ||||||||||||
result = this.getTypeBoundAt(_, _) | ||||||||||||
} | ||||||||||||
|
||||||||||||
override string toAbbreviatedString() { result = this.getName().getText() } | ||||||||||||
|
||||||||||||
override string toStringImpl() { result = this.getName().getText() } | ||||||||||||
|
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.
The string comparison
getText() = \"Self\"
is fragile and may not handle all cases where Self is referenced. Consider using a more robust type-based comparison or path resolution to identify Self references.Copilot uses AI. Check for mistakes.