-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add unpolished, experimental support for AFIDT (async fn in dyn trait) #133122
Conversation
r? @nnethercote rustbot has assigned @nnethercote. Use |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
r? types Probably best for a types team review. |
This comment has been minimized.
This comment has been minimized.
9600e7d
to
591f99f
Compare
☔ The latest upstream changes (presumably #132460) made this pull request unmergeable. Please resolve the merge conflicts. |
591f99f
to
e7fdb2e
Compare
e7fdb2e
to
e12e02d
Compare
This comment has been minimized.
This comment has been minimized.
e12e02d
to
4ffdaa3
Compare
if tcx.asyncness(fn_def_id).is_async() { | ||
return Some(MethodViolationCode::AsyncFn); | ||
if tcx.features().async_fn_in_dyn_trait() { |
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.
instead of rejecting if the feature is not enabled, we could always use code path for when the feature is enabled and just emit a feature gate error. Or are you trying to not impact stable code for now in diagnostics?
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.
I guess we could. I'm gonna leave it as a follow-up, since this needs to be reworked once again to support -> impl Future
style RPITITs.
compiler/rustc_middle/src/ty/return_position_impl_trait_in_trait.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_middle/src/ty/return_position_impl_trait_in_trait.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Outdated
Show resolved
Hide resolved
4ffdaa3
to
8989451
Compare
This comment has been minimized.
This comment has been minimized.
8989451
to
22033d1
Compare
…li-obk `fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder r? oli-obk Split out of rust-lang#133122
…li-obk `fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder r? oli-obk Split out of rust-lang#133122
…li-obk `fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder r? oli-obk Split out of rust-lang#133122
Rollup merge of rust-lang#133874 - compiler-errors:fn-sig-binder, r=oli-obk `fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder r? oli-obk Split out of rust-lang#133122
Sorry I never finished my review here >.< Looking through my drafted comments, seems like Oli got them all. |
Add unpolished, experimental support for AFIDT (async fn in dyn trait) This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`. To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`. This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error). [^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do. This could also be generalized: * To work on functions that are `-> impl Future` (soon). * To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon). Tracking: * rust-lang#133119
Add unpolished, experimental support for AFIDT (async fn in dyn trait) This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`. To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`. This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error). [^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do. This could also be generalized: * To work on functions that are `-> impl Future` (soon). * To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon). Tracking: * rust-lang#133119
Rollup of 10 pull requests Successful merges: - rust-lang#131558 (Lint on combining `#[no_mangle]` and `#[export_name]`) - rust-lang#133122 (Add unpolished, experimental support for AFIDT (async fn in dyn trait)) - rust-lang#133184 (wasi/fs: Improve stopping condition for <ReadDir as Iterator>::next) - rust-lang#133456 (Add licenses + Run `cargo update`) - rust-lang#133472 (Run TLS destructors for wasm32-wasip1-threads) - rust-lang#133853 (use vendor sources by default on dist tarballs) - rust-lang#133946 (coverage: Prefer to visit nodes whose predecessors have been visited) - rust-lang#134010 (fix ICE on type error in promoted) - rust-lang#134029 (coverage: Use a query to find counters/expressions that must be zero) - rust-lang#134071 (Configure renovatebot) r? `@ghost` `@rustbot` modify labels: rollup
3511a46
to
b482339
Compare
b482339
to
57e8a1c
Compare
Added the check for @bors r=oli-obk |
Add unpolished, experimental support for AFIDT (async fn in dyn trait) This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`. To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`. This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error). [^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do. This could also be generalized: * To work on functions that are `-> impl Future` (soon). * To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon). Tracking: * rust-lang#133119
…llaumeGomez Rollup of 8 pull requests Successful merges: - rust-lang#122003 (link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets) - rust-lang#133122 (Add unpolished, experimental support for AFIDT (async fn in dyn trait)) - rust-lang#133859 (Move some alloc tests to the alloctests crate) - rust-lang#134095 ([CI] Use a lockfile for installing the `datadog` package) - rust-lang#134155 (Forbid `unsafe_op_in_unsafe_fn` for Hurd) - rust-lang#134173 (allow `symbol_intern_string_literal` lint in test modules) - rust-lang#134178 (Stabilize the Rust 2024 prelude) - rust-lang#134179 (Remove outdated consteval note from `<*mut T>::align_offset` docs.) r? `@ghost` `@rustbot` modify labels: rollup
Add unpolished, experimental support for AFIDT (async fn in dyn trait) This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`. To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`. This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error). [^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do. This could also be generalized: * To work on functions that are `-> impl Future` (soon). * To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon). Tracking: * rust-lang#133119
Rollup of 13 pull requests Successful merges: - rust-lang#122003 (link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets) - rust-lang#133122 (Add unpolished, experimental support for AFIDT (async fn in dyn trait)) - rust-lang#133859 (Move some alloc tests to the alloctests crate) - rust-lang#134070 (Some asm! diagnostic adjustments and a papercut fix) - rust-lang#134095 ([CI] Use a lockfile for installing the `datadog` package) - rust-lang#134144 (Properly consider APITs for never type fallback ascription fix) - rust-lang#134152 (Simplify `rustc_mir_dataflow::abs_domain`.) - rust-lang#134154 (suppress field expr with generics error message if it's a method) - rust-lang#134155 (Forbid `unsafe_op_in_unsafe_fn` for Hurd) - rust-lang#134173 (allow `symbol_intern_string_literal` lint in test modules) - rust-lang#134178 (Stabilize the Rust 2024 prelude) - rust-lang#134179 (Remove outdated consteval note from `<*mut T>::align_offset` docs.) - rust-lang#134187 (Remove `PErr`.) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#133122 (Add unpolished, experimental support for AFIDT (async fn in dyn trait)) - rust-lang#133249 (ABI checks: add support for loongarch) - rust-lang#134089 (Use newly added exceptions to non default branch warning) - rust-lang#134188 (Bump Fuchsia) - rust-lang#134204 (Fix our `llvm::Bool` typedef to be signed, to match `LLVMBool`) - rust-lang#134207 (Revert "bootstrap: print{ln}! -> eprint{ln}! (take 2) rust-lang#134040") - rust-lang#134214 (rustdoc: fix self cmp) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#133122 - compiler-errors:afidt, r=oli-obk Add unpolished, experimental support for AFIDT (async fn in dyn trait) This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`. To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`. This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error). [^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do. This could also be generalized: * To work on functions that are `-> impl Future` (soon). * To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon). Tracking: * rust-lang#133119
This allows us to begin messing around
async fn
indyn Trait
. Calling an async fn from a trait object always returns adyn* Future<Output = ...>
.To make it work, Implementations are currently required to return something that can be coerced to a
dyn* Future
(see the example intests/ui/async-await/dyn/works.rs
). If it's not the right size, then it'll raise an error at the coercion site (see the example intests/ui/async-await/dyn/wrong-size.rs
). Currently the only practical way of doing this is wrapping the body inBox::pin(async move { .. })
.This PR does not implement a helper type like a "
Boxing
"1 adapter, and I'll probably follow-up with another PR to improve the error message for thePointerLike
trait (something that explains in just normal prose what is happening here, rather than a trait error).This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do.
This could also be generalized:
-> impl Future
(soon).-> impl Iterator
and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon).Tracking:
async_fn_in_dyn_trait
#133119Footnotes
https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter ↩