Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Aug 17, 2025

Instead of assigning the type Future directly, we assign dyn Future, just like we assign dyn FnOnce to closures. As @paldepind notes on that PR, using impl Future would be more faithful, but in terms of our type inference implementation the effect is the same.

DCA is fine.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Aug 17, 2025
// Type mentions required by type inference

use std::future::Future;
fn mention_dyn_future<T>(f: &dyn Future<Output = T>) {}

Check notice

Code scanning / CodeQL

Unused variable Note

Variable 'f' is not used.
use std::future::Future;
fn mention_dyn_future<T>(f: &dyn Future<Output = T>) {}

fn mention_dyn_fn_once<F>(f: &dyn FnOnce() -> F) {}

Check notice

Code scanning / CodeQL

Unused variable Note

Variable 'f' is not used.
@hvitved hvitved force-pushed the rust/type-inference-async-dyn-future branch 2 times, most recently from f847160 to f7f08f6 Compare August 19, 2025 08:28
@hvitved hvitved force-pushed the rust/type-inference-async-dyn-future branch from f7f08f6 to a9b58b8 Compare November 26, 2025 20:03
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Nov 27, 2025
@hvitved hvitved marked this pull request as ready for review November 27, 2025 06:03
@hvitved hvitved requested a review from a team as a code owner November 27, 2025 06:03
Copilot AI review requested due to automatic review settings November 27, 2025 06:03
Copilot finished reviewing on behalf of hvitved November 27, 2025 06:06
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 updates the type inference for Rust async functions to model their return types as dyn Future instead of the raw Future trait type. This change aligns with how closures are already modeled as dyn FnOnce, providing consistency in the type system representation. The change affects both async blocks and async functions.

  • Introduces a new mentions.rs file to ensure the dyn Future and dyn FnOnce types are available in the type system
  • Updates type inference logic to use dyn Future with appropriate type parameters
  • Adjusts test expectations to reflect the new type representation (from trait Future to dyn Future and from Output to dyn(Output))

Reviewed changes

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

File Description
rust/tools/builtins/mentions.rs New file that declares type mentions for dyn Future and dyn FnOnce to ensure these trait object types are available for type inference
rust/ql/test/library-tests/type-inference/type-inference.expected Updated test expectations to reflect async return types now being represented as dyn Future with dyn(Output) parameters instead of trait Future with Output parameters
rust/ql/lib/codeql/rust/internal/TypeInference.qll Core implementation changes: updated getFutureTraitType() to return DynTraitType, added getDynFutureOutputTypeParameter() helper, and replaced references to use the new dyn-based type parameters throughout async handling code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@paldepind paldepind left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for doing this.

@hvitved hvitved merged commit f0cac32 into github:main Nov 27, 2025
28 checks passed
@hvitved hvitved deleted the rust/type-inference-async-dyn-future branch November 27, 2025 08:41
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