Rust: Add predicates for fieldless and unit-only enums#20906
Merged
paldepind merged 4 commits intogithub:mainfrom Nov 26, 2025
Merged
Rust: Add predicates for fieldless and unit-only enums#20906paldepind merged 4 commits intogithub:mainfrom
paldepind merged 4 commits intogithub:mainfrom
Conversation
f0f1ff5 to
4f13ae3
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines the CodeQL Rust library's handling of enum and struct predicates to align with Rust terminology and adds new predicates for classifying enum types.
- Changes
isStruct()predicates to check for actual struct field lists rather than using negation logic - Adds
isUnit()predicates for structs and variants without field lists - Introduces
isFieldless()andisUnitOnly()predicates for enums with comprehensive test coverage
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
rust/ql/test/library-tests/elements/enum/enums.rs |
Adds test data with four enum examples covering unit-only, fieldless, and field-containing enums |
rust/ql/test/library-tests/elements/enum/Enum.ql |
Adds test queries for the new isFieldless() and isUnitOnly() predicates |
rust/ql/test/library-tests/elements/enum/Enum.expected |
Defines expected test results showing correct classification of enums |
rust/ql/test/library-tests/elements/enum/Cargo.lock |
Standard Cargo lock file for test project |
rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll |
Refactors isStruct() to check field list type, adds isUnit() and getNumberOfFields() predicates |
rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll |
Refactors isStruct() to check field list type and adds isUnit() predicate |
rust/ql/lib/codeql/rust/elements/internal/EnumImpl.qll |
Implements new isFieldless() and isUnitOnly() predicates with proper documentation |
rust/ql/lib/codeql/rust/internal/TypeInference.qll |
Updates struct/variant declarations to include unit types alongside struct types |
rust/ql/lib/codeql/rust/internal/PathResolution.qll |
Updates namespace resolution to use isStruct() predicate instead of checking field list type directly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR:
isStructpredicates forStructandEnum. Including unit-like structs/enums in this was inconsistent with Rust terminology.Enumfor fieldless and unit-only enums. I think the fieldless notion can be very useful as barriers, similar to what we have for numbers and booleans. A fieldless enum can't cary sensitive data or do injections. I also want to use it over in Rust: Lift content reads as taint steps #20879.The DCA report is clean 👍