Add unpolished, experimental support for AFIDT (async fn in dyn trait) #133122
+679
−128
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ↩