Rust: Don't propagate impl in return position into function bodies#21019
Merged
paldepind merged 1 commit intogithub:mainfrom Dec 12, 2025
Merged
Rust: Don't propagate impl in return position into function bodies#21019paldepind merged 1 commit intogithub:mainfrom
impl in return position into function bodies#21019paldepind merged 1 commit intogithub:mainfrom
Conversation
ac1b08c to
4425891
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Rust type inference by preventing impl Trait return types from being propagated into function bodies. The change correctly recognizes that impl Trait in return position is an abstraction for function consumers, not the actual type used within the function implementation.
Key changes:
- Refactored function body type inference to filter out
impl Traitreturn types - Function bodies now correctly infer concrete types instead of opaque
impl Traittypes - Updated test expectations to reflect the corrected type inference behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/internal/TypeInference.qll | Refactored type annotation logic by extracting function body type inference into a dedicated predicate with proper filtering to exclude ImplTraitReturnType and its type parameters |
| rust/ql/test/library-tests/type-inference/type-inference.expected | Auto-generated test expectations showing that function bodies now infer concrete types (e.g., dyn Future, S1, S2) instead of impl Trait types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
With this PR: When an
impl Traittype appears in a function's return type annotation, don't propagate it into the function itself.I think this makes more sense as the annotation is for users of the function, and it's on purpose not the correct type to use inside the function.