-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Implement toString for struct fields and visibility
#20924
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
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 implements custom toString methods for StructField and Visibility AST nodes in the Rust CodeQL library, improving their string representations from generic class names to meaningful syntax-based descriptions.
- Implements
toStringforVisibilityto displaypuborpub(path)instead ofVisibility - Implements
toStringforStructFieldto display field signatures likefield: typeorpub field: type - Updates all test expectations to reflect the new string representations
Reviewed changes
Copilot reviewed 7 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
rust/ql/lib/codeql/rust/elements/internal/VisibilityImpl.qll |
Implements toStringImpl and toAbbreviatedString for Visibility to render as pub or pub(path) |
rust/ql/lib/codeql/rust/elements/internal/StructFieldImpl.qll |
Implements toStringImpl for StructField to render field signatures with optional visibility, name, and type |
rust/ql/.gitattributes |
Removes VisibilityImpl.qll from linguist-generated list since it's now hand-modified |
rust/ql/.generated.list |
Removes VisibilityImpl.qll from the generated files list |
rust/ql/test/extractor-tests/utf8/ast.expected |
Updates test expectations for Visibility and StructField toString output |
rust/ql/test/extractor-tests/macro-in-library/PrintAst.expected |
Updates test expectations for Visibility toString output |
rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected |
Updates test expectations for Visibility and StructField toString output |
rust/ql/test/extractor-tests/generated/Visibility/Visibility.expected |
Updates test expectations for Visibility instances |
rust/ql/test/extractor-tests/generated/Trait/Trait.expected |
Updates test expectations for Visibility in trait declarations |
rust/ql/test/extractor-tests/generated/StructFieldList/StructFieldList.expected |
Updates test expectations for StructField instances in field lists |
rust/ql/test/extractor-tests/generated/StructField/StructField.expected |
Updates test expectations for StructField instances |
rust/ql/test/extractor-tests/generated/Module/Module.expected |
Updates test expectations for Visibility in module declarations |
rust/ql/test/extractor-tests/generated/MacroDef/MacroDef.expected |
Updates test expectations for Visibility in macro definitions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hvitved
left a comment
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.
LGTM, one minor thing.
| /** Holds if this record field is named `name` and belongs to the struct `s`. */ | ||
| predicate isStructField(Struct s, string name) { this = s.getStructField(name) } | ||
|
|
||
| override string toStringImpl() { result = concat(int i | | this.toStringPart(i) order by i) } |
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.
strictconcat.
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.
Done. But I don't really understand why. It doesn't make a difference here does it? Should we use strictconcat in all toStringImpls (like this one)?
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.
strictconcat produces slightly simpler DIL; it is generally always preferable to use strict aggregates when we know that the range is non-empty.
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.
Thanks. So the answer to the second question is: yes, we should also use strictconcat in the other toStringImpls.
Implements
toStringforStructFieldandVisibility.