-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Include synthetic type parameters in Type.getATypeParameter
#20274
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
Conversation
008231b
to
9ef839d
Compare
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.
Pull Request Overview
This PR modifies the type parameter handling in Rust to properly include synthetic type parameters (such as associated types in traits) in Type.getATypeParameter()
. The changes address an issue where the certainTypeConflict
check wasn't working correctly for synthetic type parameters.
- Separates positional type parameters from all type parameters by introducing
getPositionalTypeParameter()
- Updates
getATypeParameter()
to include both positional and synthetic type parameters - Adds specific handling for trait and dynamic trait types to include their associated types
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
rust/ql/lib/codeql/rust/internal/Type.qll | Refactors type parameter methods and adds synthetic type parameter support for trait types |
rust/ql/lib/codeql/rust/internal/TypeMention.qll | Updates call to use the new positional type parameter method |
* This includes both positional type parameters and synthetic type parameters, | ||
* such as associated types in traits. | ||
*/ | ||
TypeParameter getATypeParameter() { result = this.getPositionalTypeParameter(_) } |
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 default implementation of getATypeParameter()
only returns positional type parameters. This means that types like StructType
, EnumType
, etc. won't include their synthetic type parameters unless they override this method. Consider making this method abstract or providing a more comprehensive default implementation.
TypeParameter getATypeParameter() { result = this.getPositionalTypeParameter(_) } | |
abstract TypeParameter getATypeParameter(); |
Copilot uses AI. Check for mistakes.
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.
I think this is a great change!
The way I understand it, #19847 got rid of the annoying traitAliasIndex
that assigned arbitrary indices to associated types for traits. But, it also meant that getTypeParameter
on traits no longer gave the tp's for associated types.
With this PR we get the best of both worlds: A getATypeParameter
that gives the full set of type parameters (without requiring one to invent positions where it doesn't make much sense) and a getPositionalTypeParameter
that holds for the subset of the TPs that have a meaningful position.
#20179 follow-up: The
not certainType.getATypeParameter() = tp
check incertainTypeConflict
does not work as intended for synthetic type parameters.DCA is uneventful.