Type inference: Generalize `typeConstraintBaseTypeMatch` by hvitved · Pull Request #22052 · github/codeql · GitHub
Skip to content

Type inference: Generalize typeConstraintBaseTypeMatch#22052

Open
hvitved wants to merge 2 commits into
github:mainfrom
hvitved:rust/type-constraint-base-type-match-gen
Open

Type inference: Generalize typeConstraintBaseTypeMatch#22052
hvitved wants to merge 2 commits into
github:mainfrom
hvitved:rust/type-constraint-base-type-match-gen

Conversation

@hvitved

@hvitved hvitved commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

The logic in typeConstraintBaseTypeMatch was previously hard-coded to only look at type parameters that could be directly matched via the type of an argument, but it is both more general and clean to use the typeMatch predicate (to which typeConstraintBaseTypeMatch also itself contributes). I have added a test case that shows how this allows us to infer more types.

DCA is uneventful, except there is an increase in Nodes With Type At Length Limit for rendiation, but that will be fixed once #21795 is merged (this PR was extracted from that PR).

@hvitved hvitved force-pushed the rust/type-constraint-base-type-match-gen branch from 4909d80 to 36724d8 Compare June 25, 2026 15:05
@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Jun 25, 2026
@hvitved hvitved force-pushed the rust/type-constraint-base-type-match-gen branch from 36724d8 to 8cfb152 Compare June 29, 2026 07:51
@hvitved

hvitved commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@hvitved hvitved changed the title Shared: Generalize typeConstraintBaseTypeMatch Type inference: Generalize typeConstraintBaseTypeMatch Jun 29, 2026
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Jun 29, 2026
@hvitved hvitved marked this pull request as ready for review June 29, 2026 11:40
@hvitved hvitved requested review from a team as code owners June 29, 2026 11:40
Copilot AI review requested due to automatic review settings June 29, 2026 11:40

Copilot AI 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 generalizes typeConstraintBaseTypeMatch to reuse the existing typeMatch infrastructure, enabling more general type inference through constraints. It also adds a Rust regression test demonstrating the newly inferred types and updates a consistency expected file to reflect shifted line numbers.

Changes:

  • Refactor type-constraint-based inference to use typeMatch more broadly (and adjust related access/constraint plumbing).
  • Add a Rust test case covering inference through a chained trait constraint (MyTrait2<T2> where T2: MyTrait<T1>).
  • Update the Rust path-resolution consistency expected output to match new source locations.
Show a summary per file
File Description
shared/typeinference/codeql/typeinference/internal/TypeInference.qll Generalizes constraint/type matching logic; (docs in the touched area need updating to reflect the new predicate signatures/semantics).
rust/ql/test/library-tests/type-inference/main.rs Adds a new trait/impl/call chain to exercise improved inference.
rust/ql/test/library-tests/type-inference/CONSISTENCY/PathResolutionConsistency.expected Updates expected locations after line shifts in main.rs.

Review details

  • Files reviewed: 3/4 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread shared/typeinference/codeql/typeinference/internal/TypeInference.qll Outdated
@hvitved hvitved force-pushed the rust/type-constraint-base-type-match-gen branch from 8cfb152 to bfc37e5 Compare June 29, 2026 11:57
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