Rust: Remove restriction that blanket(-like) impls must have a constraint#21168
Merged
hvitved merged 2 commits intogithub:mainfrom Jan 21, 2026
Merged
Conversation
326464f to
f7df602
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes the restriction that blanket implementations must have constraints, enabling resolution of calls like impl<T> From<T> for T. The change improves call target resolution by allowing blanket implementations when no compatible non-blanket targets exist, preventing ambiguous call targets through a specialization-aware disambiguation strategy.
Changes:
- Modified type inference logic to handle blanket implementations without constraints
- Added new predicate to check if arguments are NOT instantiations of function parameters
- Extended blanket implementation constraint checking to handle unconstrained type parameters
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/test/library-tests/type-inference/main.rs | Updated test comment to expect call target resolution for blanket impl |
| rust/ql/test/library-tests/dataflow/local/main.rs | Updated comments to reflect new flow summaries for reflexive From and Into implementations |
| rust/ql/test/library-tests/dataflow/local/inline-flow.expected | Added new flow summaries for Into trait and updated MaD references to reflect new model numbering |
| rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll | Added disambiguation logic to prefer non-blanket implementations and check for type parameter constraints |
| rust/ql/lib/codeql/rust/internal/typeinference/FunctionType.qll | Renamed module and added predicate to detect non-matching type instantiations |
| rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll | Extended sibling detection to handle multiple blanket implementations |
| rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll | Extended constraint satisfaction to handle blanket impls without non-trivial constraints |
| rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll | Added flow summary for reflexive From implementation that preserves values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll
Outdated
Show resolved
Hide resolved
rust/ql/lib/codeql/rust/internal/typeinference/BlanketImplementation.qll
Show resolved
Hide resolved
f7df602 to
fd309d6
Compare
paldepind
requested changes
Jan 20, 2026
Contributor
paldepind
left a comment
There was a problem hiding this comment.
Very nice improvements to the number of resolved calls!
rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll
Outdated
Show resolved
Hide resolved
rust/ql/lib/codeql/rust/internal/typeinference/FunctionOverloading.qll
Outdated
Show resolved
Hide resolved
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
paldepind
previously approved these changes
Jan 20, 2026
ee85c9e to
f76d85c
Compare
paldepind
approved these changes
Jan 21, 2026
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.
Before this PR, blanket implementations without constraints, such as
impl<T> From<T> for T, were ignored, because they would give rise to too many calls with multiple call targets.This PR changes that, and avoids multiple targets by only allowing blanket targets when no compatible non-blanket targets exist (we already had this check in place for method calls).
DCA looks good:
Percentage of calls with call targetincreases by 1.5 % point and performance is more or less unchanged.