Skip to content

Rust: Model union, never, and pointer types - #20516

Merged
hvitved merged 2 commits into
github:mainfrom
hvitved:rust/type-inference-union-pointer-never
Sep 26, 2025
Merged

Rust: Model union, never, and pointer types#20516
hvitved merged 2 commits into
github:mainfrom
hvitved:rust/type-inference-union-pointer-never

Conversation

@hvitved

@hvitvedhvitved commented Sep 25, 2025

Copy link
Copy Markdown
Contributor

Extracted from #20282.

DCA looks good: increase in resolvable calls by 0.353 % points.

@github-actionsgithub-actionsBot added the Rust Pull requests that update Rust code label Sep 25, 2025
@hvitved
hvitvedforce-pushed the rust/type-inference-union-pointer-never branch from 633926e to 2a814ddCompareSeptember 25, 2025 10:34
@hvitvedhvitved added the no-change-note-required This PR does not need a change note label Sep 25, 2025
@hvitved
hvitved marked this pull request as ready for review September 25, 2025 14:15
@hvitved
hvitved requested a review from a team as a code ownerSeptember 25, 2025 14:15
CopilotAI review requested due to automatic review settings September 25, 2025 14:15

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 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
FileDescription
rust/ql/lib/codeql/rust/internal/Type.qllAdds UnionType, NeverType, and PtrType classes with their type parameters
rust/ql/lib/codeql/rust/internal/TypeMention.qllAdds type mention classes for never and pointer type representations
rust/ql/lib/codeql/rust/internal/TypeInference.qllExtends type inference to handle pointer type parameters
rust/ql/lib/codeql/rust/elements/internal/UnionImpl.qllAdds getStructField method to Union class for field access
rust/ql/test/library-tests/type-inference/type-inference.expectedTest expectations updated to reflect improved never type inference
rust/ql/test/query-tests/security/CWE-770/CONSISTENCY/PathResolutionConsistency.expectedTest expectations for improved call resolution with pointer casts
rust/ql/test/query-tests/security/CWE-696/CONSISTENCY/PathResolutionConsistency.expectedTest expectations for improved call resolution with pointer operations
rust/ql/test/extractor-tests/macro-expansion/CONSISTENCY/TypeInferenceConsistency.expectedRemoves previous type inference inconsistency for union types

@paldepindpaldepind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One tiny comment, otherwise looks really good!

Comment threadrust/ql/lib/codeql/rust/elements/internal/UnionImpl.qll Outdated
Co-authored-by: Simon Friis Vindum <paldepind@github.com>

@paldepindpaldepind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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!

@hvitved
hvitved merged commit c52709a into github:mainSep 26, 2025
18 checks passed
@hvitved
hvitved deleted the rust/type-inference-union-pointer-never branch September 26, 2025 08:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-requiredThis PR does not need a change noteRustPull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@hvitved@paldepind