Skip to content

Conversation

@paldepind
Copy link
Contributor

@paldepind paldepind commented Nov 27, 2025

Implements toString for StructField and Visibility.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Nov 27, 2025
@paldepind paldepind marked this pull request as ready for review November 27, 2025 11:48
@paldepind paldepind requested a review from a team as a code owner November 27, 2025 11:48
Copilot AI review requested due to automatic review settings November 27, 2025 11:48
Copilot finished reviewing on behalf of paldepind November 27, 2025 11:52
Copy link
Contributor

Copilot AI left a 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 toString for Visibility to display pub or pub(path) instead of Visibility
  • Implements toString for StructField to display field signatures like field: type or pub 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.

@paldepind paldepind added the no-change-note-required This PR does not need a change note label Nov 27, 2025
Copy link
Contributor

@hvitved hvitved left a 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) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strictconcat.

Copy link
Contributor Author

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)?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@paldepind paldepind requested a review from hvitved December 1, 2025 13:03
@paldepind paldepind merged commit 87d6a60 into github:main Dec 1, 2025
18 checks passed
@paldepind paldepind deleted the rust/struct-field-tostring branch December 1, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants