-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Model async return types as dyn Future
#20236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust: Model async return types as dyn Future
#20236
Conversation
| // 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
| 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
f847160 to
f7f08f6
Compare
f7f08f6 to
a9b58b8
Compare
There was a problem hiding this 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.rsfile to ensure thedyn Futureanddyn FnOncetypes are available in the type system - Updates type inference logic to use
dyn Futurewith appropriate type parameters - Adjusts test expectations to reflect the new type representation (from
trait Futuretodyn Futureand fromOutputtodyn(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.
paldepind
left a comment
There was a problem hiding this 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.
Instead of assigning the type
Futuredirectly, we assigndyn Future, just like we assigndyn FnOnceto closures. As @paldepind notes on that PR, usingimpl Futurewould be more faithful, but in terms of our type inference implementation the effect is the same.DCA is fine.