-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||
result = wp.getTypeBoundList().getBound(index - this.nrOfDirectTypeBounds()) | ||
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. It appears to be legal to have two where predicates with
I think at the moment this will break your index numbering. 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. You're right, that is legal and the implementation currently does not account for that. |
||
) | ||
} | ||
|
||
/** | ||
* Gets a type bound of this trait. | ||
* | ||
* This includes type bounds directly on the trait and bounds from any | ||
* `where` clauses for `Self`. | ||
*/ | ||
TypeBound getATypeBound() { result = this.getTypeBound(_) } | ||
} | ||
} |
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,36 @@ module Impl { | |
/** Gets the position of this type parameter. */ | ||
int getPosition() { this = any(GenericParamList l).getTypeParam(result) } | ||
|
||
private int nrOfDirectTypeBounds() { | ||
result = this.getTypeBoundList().getNumberOfBounds() | ||
or | ||
not this.hasTypeBoundList() and | ||
result = 0 | ||
} | ||
|
||
/** | ||
* 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) { | ||
|
||
exists(TypeBoundList tbl, int offset | result = tbl.getBound(index - offset) | | ||
tbl = this.getTypeBoundList() and offset = 0 | ||
or | ||
tbl = this.(TypeParamItemNode).getAWherePred().getTypeBoundList() and | ||
offset = this.nrOfDirectTypeBounds() | ||
paldepind marked this conversation as resolved.
Show resolved
Hide resolved
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. Again I think the index numbering breaks if there's more than one applicable |
||
) | ||
} | ||
|
||
/** | ||
* 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() { result = this.getTypeBound(_) } | ||
|
||
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.