Rust: Model union, never, and pointer types#20516
Merged
hvitved merged 2 commits intogithub:mainfrom Sep 26, 2025
Merged
Conversation
633926e to
2a814dd
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for modeling union, never (!), and pointer types in Rust's type system. The changes enhance the type inference system to better handle these Rust type constructs, resulting in improved call resolution capabilities.
Key changes:
- Added new type representations for union, never, and pointer types to the type system
- Extended type mention resolution to handle these new type constructs
- Updated type inference logic to support pointer type parameters
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/internal/Type.qll | Adds UnionType, NeverType, and PtrType classes with their type parameters |
| rust/ql/lib/codeql/rust/internal/TypeMention.qll | Adds type mention classes for never and pointer type representations |
| rust/ql/lib/codeql/rust/internal/TypeInference.qll | Extends type inference to handle pointer type parameters |
| rust/ql/lib/codeql/rust/elements/internal/UnionImpl.qll | Adds getStructField method to Union class for field access |
| rust/ql/test/library-tests/type-inference/type-inference.expected | Test expectations updated to reflect improved never type inference |
| rust/ql/test/query-tests/security/CWE-770/CONSISTENCY/PathResolutionConsistency.expected | Test expectations for improved call resolution with pointer casts |
| rust/ql/test/query-tests/security/CWE-696/CONSISTENCY/PathResolutionConsistency.expected | Test expectations for improved call resolution with pointer operations |
| rust/ql/test/extractor-tests/macro-expansion/CONSISTENCY/TypeInferenceConsistency.expected | Removes previous type inference inconsistency for union types |
paldepind
requested changes
Sep 26, 2025
Contributor
paldepind
left a comment
There was a problem hiding this comment.
One tiny comment, otherwise looks really good!
Co-authored-by: Simon Friis Vindum <paldepind@github.com>
paldepind
approved these changes
Sep 26, 2025
Contributor
paldepind
left a comment
There was a problem hiding this comment.
Nice! With this I think we have support for all forms of types in Rust (maybe with the exception of function pointer types) which is really great!
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.
Extracted from #20282.
DCA looks good: increase in resolvable calls by
0.353 %points.