Rust: Unify handling of struct and tuple constructors#21488
Open
paldepind wants to merge 2 commits intogithub:mainfrom
Open
Rust: Unify handling of struct and tuple constructors#21488paldepind wants to merge 2 commits intogithub:mainfrom
paldepind wants to merge 2 commits intogithub:mainfrom
Conversation
3f392e8 to
b25b78b
Compare
b25b78b to
97670b3
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors Rust type inference to unify handling of struct-like and tuple-like struct/variant constructors and their corresponding patterns, reducing duplicated matching/configuration logic.
Changes:
- Unifies constructor type inference for tuple-struct calls, struct expressions, and nullary path expressions under a single matching configuration.
- Unifies pattern type inference for struct patterns and tuple-struct patterns under a single matching configuration.
- Adds
getNthStructField(int i)helpers onStruct,Variant,StructExpr, andStructPatwrappers to support index-based field access.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll | Consolidates constructor and constructor-pattern inference paths into shared matching modules. |
| rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll | Adds getNthStructField helper to support unified constructor handling. |
| rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll | Adds getNthStructField helper to support unified constructor handling. |
| rust/ql/lib/codeql/rust/elements/internal/StructPatImpl.qll | Adds getNthStructField helper for resolved struct/variant fields in patterns. |
| rust/ql/lib/codeql/rust/elements/internal/StructExprImpl.qll | Adds getNthStructField helper for instantiated struct/variant fields in expressions. |
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll
Outdated
Show resolved
Hide resolved
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Removes some code duplication by unifying handling of tuple-like and struct-like structs and variants in type inference.