Skip to content

Rust: Take additional type parameter constraints into account#21564

Open
hvitved wants to merge 3 commits intogithub:mainfrom
hvitved:rust/type-inference-additional-constraints
Open

Rust: Take additional type parameter constraints into account#21564
hvitved wants to merge 3 commits intogithub:mainfrom
hvitved:rust/type-inference-additional-constraints

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Mar 24, 2026

For example, in

impl<T> SomeType<T> where T: Clone {
    fn foo() where T: Debug { }
}

the constraint Debug additionally applies to T in foo, which was previously not taken into account.

DCA is good; more resolved calls, more alerts, little performance impact.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Mar 24, 2026
@hvitved hvitved force-pushed the rust/type-inference-additional-constraints branch from 8104bdc to 7fd1e6b Compare March 24, 2026 13:18
@hvitved hvitved force-pushed the rust/type-inference-additional-constraints branch from 7fd1e6b to 6295f57 Compare March 25, 2026 09:12
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Mar 25, 2026
@hvitved hvitved marked this pull request as ready for review March 25, 2026 13:44
@hvitved hvitved requested review from a team as code owners March 25, 2026 13:44
@hvitved hvitved requested review from Copilot and paldepind March 25, 2026 13:44
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 improves Rust call/type resolution by incorporating additional type-parameter constraints introduced on inner items (for example, method-level where clauses) so that these constraints are considered during trait lookup and type inference.

Changes:

  • Extend the shared type-inference matching interfaces to allow retrieving type-parameter constraints in a declaration-scoped way.
  • Add Rust support for “additional” bounds (derived from constraining items) and thread that context into lookup-trait substitution used by associated-function resolution.
  • Update/extend regression and model-generator tests to reflect improved resolution.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
shared/typeinference/codeql/typeinference/internal/TypeInference.qll Adds a decl-scoped type-parameter constraint accessor and wires it into matching logic.
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll Incorporates additional per-declaration type-parameter constraints into Rust matching/resolution.
rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll Makes lookup-trait substitution context-aware (AST/item context) to include additional bounds.
rust/ql/lib/codeql/rust/internal/PathResolution.qll Exposes resolution of additional bounds for type parameters relative to a constraining item.
rust/ql/lib/codeql/rust/elements/internal/TypeParamImpl.qll Adds API to retrieve additional type bounds applying to a specific constraining item.
rust/ql/test/utils-tests/modelgenerator/option.rs Updates expected model-generator summary annotations now that resolution improves.
rust/ql/test/library-tests/type-inference/regressions.rs Adds a regression covering method-level constraints affecting trait method resolution.
rust/ql/test/library-tests/type-inference/type-inference.expected Updates expected inference results to match improved resolution.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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