Add lang items for AsyncFn's associated types

This commit is contained in:
Michael Goulet 2024-05-29 14:06:39 -04:00
parent f2e1a3a80a
commit 7f11d6f4bf
4 changed files with 23 additions and 8 deletions

View File

@ -228,6 +228,9 @@ language_item_table! {
AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1); AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1);
AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1); AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1); AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
AsyncFnOnceOutput, sym::async_fn_once_output,async_fn_once_output, Target::AssocTy, GenericRequirement::Exact(1);
CallOnceFuture, sym::call_once_future, call_once_future, Target::AssocTy, GenericRequirement::Exact(1);
CallRefFuture, sym::call_ref_future, call_ref_future, Target::AssocTy, GenericRequirement::Exact(2);
AsyncFnKindHelper, sym::async_fn_kind_helper,async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1); AsyncFnKindHelper, sym::async_fn_kind_helper,async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1);
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None; FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;

View File

@ -441,6 +441,7 @@ symbols! {
async_fn_kind_helper, async_fn_kind_helper,
async_fn_mut, async_fn_mut,
async_fn_once, async_fn_once,
async_fn_once_output,
async_fn_track_caller, async_fn_track_caller,
async_fn_traits, async_fn_traits,
async_for_loop, async_for_loop,
@ -498,6 +499,8 @@ symbols! {
call, call,
call_mut, call_mut,
call_once, call_once,
call_once_future,
call_ref_future,
caller_location, caller_location,
capture_disjoint_fields, capture_disjoint_fields,
catch_unwind, catch_unwind,

View File

@ -407,16 +407,20 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
output_coroutine_ty, output_coroutine_ty,
coroutine_return_ty, coroutine_return_ty,
}| { }| {
let (projection_term, term) = match tcx.item_name(goal.predicate.def_id()) { let lang_items = tcx.lang_items();
sym::CallOnceFuture => ( let (projection_term, term) = if Some(goal.predicate.def_id())
== lang_items.call_once_future()
{
(
ty::AliasTerm::new( ty::AliasTerm::new(
tcx, tcx,
goal.predicate.def_id(), goal.predicate.def_id(),
[goal.predicate.self_ty(), tupled_inputs_ty], [goal.predicate.self_ty(), tupled_inputs_ty],
), ),
output_coroutine_ty.into(), output_coroutine_ty.into(),
), )
sym::CallRefFuture => ( } else if Some(goal.predicate.def_id()) == lang_items.call_ref_future() {
(
ty::AliasTerm::new( ty::AliasTerm::new(
tcx, tcx,
goal.predicate.def_id(), goal.predicate.def_id(),
@ -427,8 +431,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
], ],
), ),
output_coroutine_ty.into(), output_coroutine_ty.into(),
), )
sym::Output => ( } else if Some(goal.predicate.def_id()) == lang_items.async_fn_once_output() {
(
ty::AliasTerm::new( ty::AliasTerm::new(
tcx, tcx,
goal.predicate.def_id(), goal.predicate.def_id(),
@ -438,8 +443,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
], ],
), ),
coroutine_return_ty.into(), coroutine_return_ty.into(),
), )
name => bug!("no such associated type: {name}"), } else {
bug!("no such associated type in `AsyncFn*`: {:?}", goal.predicate.def_id())
}; };
ty::ProjectionPredicate { projection_term, term } ty::ProjectionPredicate { projection_term, term }
}, },

View File

@ -26,6 +26,7 @@ pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> { pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
/// Future returned by [`AsyncFnMut::async_call_mut`] and [`AsyncFn::async_call`]. /// Future returned by [`AsyncFnMut::async_call_mut`] and [`AsyncFn::async_call`].
#[unstable(feature = "async_fn_traits", issue = "none")] #[unstable(feature = "async_fn_traits", issue = "none")]
#[cfg_attr(not(bootstrap), lang = "call_ref_future")]
type CallRefFuture<'a>: Future<Output = Self::Output> type CallRefFuture<'a>: Future<Output = Self::Output>
where where
Self: 'a; Self: 'a;
@ -46,10 +47,12 @@ pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
pub trait AsyncFnOnce<Args: Tuple> { pub trait AsyncFnOnce<Args: Tuple> {
/// Future returned by [`AsyncFnOnce::async_call_once`]. /// Future returned by [`AsyncFnOnce::async_call_once`].
#[unstable(feature = "async_fn_traits", issue = "none")] #[unstable(feature = "async_fn_traits", issue = "none")]
#[cfg_attr(not(bootstrap), lang = "call_once_future")]
type CallOnceFuture: Future<Output = Self::Output>; type CallOnceFuture: Future<Output = Self::Output>;
/// Output type of the called closure's future. /// Output type of the called closure's future.
#[unstable(feature = "async_fn_traits", issue = "none")] #[unstable(feature = "async_fn_traits", issue = "none")]
#[cfg_attr(not(bootstrap), lang = "async_fn_once_output")]
type Output; type Output;
/// Call the [`AsyncFnOnce`], returning a future which may move out of the called closure. /// Call the [`AsyncFnOnce`], returning a future which may move out of the called closure.