Skip to content

Conversation

@paldepind
Copy link
Contributor

@paldepind paldepind commented Jan 9, 2026

In the special FnOnce(Args) -> ReturnType syntax, the return type can be omitted which is equivalent to specifying () as the return type.

I moved the handling of this from getTypeMentionForTypeParameter to getTypeForTypeParameterAt since we now have a case where a suitable type mention is present.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jan 9, 2026
@paldepind paldepind marked this pull request as ready for review January 12, 2026 07:28
@paldepind paldepind requested a review from a team as a code owner January 12, 2026 07:28
Copilot AI review requested due to automatic review settings January 12, 2026 07:28
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 implements proper handling for Rust function trait syntax when the return type is omitted, making it default to the unit type () as per Rust language semantics. This aligns with Rust's specification where FnOnce(Args) is equivalent to FnOnce(Args) -> ().

Changes:

  • Added logic to handle omitted return types in function trait syntax, defaulting to unit type
  • Moved function trait handling from getTypeMentionForTypeParameter to getTypeForTypeParameterAt to better reflect that a suitable type mention is present
  • Added test case to verify the behavior

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
rust/ql/test/library-tests/type-inference/closure.rs Added test case for FnOnce(bool) without return type to verify it defaults to ()
rust/ql/test/library-tests/type-inference/type-inference.expected Updated expected test results with new inferences and shifted line numbers
rust/ql/lib/codeql/rust/internal/TypeMention.qll Moved and enhanced function trait handling logic to properly support omitted return 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 Jan 12, 2026
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