Skip to content

Rust: Unify handling of struct and tuple constructors#21488

Open
paldepind wants to merge 2 commits intogithub:mainfrom
paldepind:rust/tuple-constructor-self
Open

Rust: Unify handling of struct and tuple constructors#21488
paldepind wants to merge 2 commits intogithub:mainfrom
paldepind:rust/tuple-constructor-self

Conversation

@paldepind
Copy link
Contributor

@paldepind paldepind commented Mar 17, 2026

Removes some code duplication by unifying handling of tuple-like and struct-like structs and variants in type inference.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Mar 17, 2026
@paldepind paldepind force-pushed the rust/tuple-constructor-self branch from 3f392e8 to b25b78b Compare March 17, 2026 15:32
@paldepind paldepind changed the title Rust: Remove type at self position for tuple-like constructors Rust: Unify handling of struct and tuple constructors Mar 17, 2026
@paldepind paldepind force-pushed the rust/tuple-constructor-self branch from b25b78b to 97670b3 Compare March 17, 2026 15:53
@paldepind paldepind marked this pull request as ready for review March 17, 2026 16:21
@paldepind paldepind requested a review from a team as a code owner March 17, 2026 16:21
Copilot AI review requested due to automatic review settings March 17, 2026 16:21
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 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 on Struct, Variant, StructExpr, and StructPat wrappers 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.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@paldepind paldepind added the no-change-note-required This PR does not need a change note label Mar 17, 2026
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