Rust: Take additional type parameter constraints into account#21564
Open
hvitved wants to merge 3 commits intogithub:mainfrom
Open
Rust: Take additional type parameter constraints into account#21564hvitved wants to merge 3 commits intogithub:mainfrom
hvitved wants to merge 3 commits intogithub:mainfrom
Conversation
8104bdc to
7fd1e6b
Compare
7fd1e6b to
6295f57
Compare
Contributor
There was a problem hiding this comment.
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. |
rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <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.
For example, in
the constraint
Debugadditionally applies toTinfoo, which was previously not taken into account.DCA is good; more resolved calls, more alerts, little performance impact.