-
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 #20140
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
ce60fb9
2313011
c6fb8c1
69ca7ff
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -36,5 +36,36 @@ module Impl { | |||||
| not this.hasGenericParamList() and | ||||||
| result = 0 | ||||||
| } | ||||||
|
|
||||||
| private int nrOfDirectTypeBounds() { | ||||||
| result = this.getTypeBoundList().getNumberOfBounds() | ||||||
| or | ||||||
| not this.hasTypeBoundList() and | ||||||
| result = 0 | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Gets the `index`th type bound of this trait, if any. | ||||||
| * | ||||||
| * This includes type bounds directly on the trait and bounds from any | ||||||
| * `where` clauses for `Self`. | ||||||
| */ | ||||||
| TypeBound getTypeBound(int index) { | ||||||
| result = this.getTypeBoundList().getBound(index) | ||||||
| or | ||||||
| exists(WherePred wp | | ||||||
| wp = this.getWhereClause().getAPredicate() and | ||||||
| wp.getTypeRepr().(PathTypeRepr).getPath().getText() = "Self" and | ||||||
|
||||||
| wp.getTypeRepr().(PathTypeRepr).getPath().getText() = "Self" and | |
| wp.getTypeRepr() instanceof SelfTypeRepr and |
geoffw0 marked this conversation as resolved.
Show resolved
Hide resolved
| 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) | ||
| ) | ||
geoffw0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| } | ||
|
||
|
|
||
| /** | ||
| * 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() } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.