Skip to content

Conversation

@paldepind
Copy link
Contributor

@paldepind paldepind commented Dec 12, 2025

With this PR: When an impl Trait type 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.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Dec 12, 2025
@paldepind paldepind marked this pull request as ready for review December 12, 2025 08:29
@paldepind paldepind requested a review from a team as a code owner December 12, 2025 08:29
Copilot AI review requested due to automatic review settings December 12, 2025 08:29
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 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 Trait return types
  • Function bodies now correctly infer concrete types instead of opaque impl Trait types
  • 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.

@paldepind paldepind added the no-change-note-required This PR does not need a change note label Dec 12, 2025
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

@paldepind paldepind merged commit c5987b4 into github:main Dec 12, 2025
26 of 27 checks passed
@paldepind paldepind deleted the rust/impl-return branch December 12, 2025 10:32
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