Skip to content

Commit 7f11d6f

Browse files
Add lang items for AsyncFn's associated types
1 parent f2e1a3a commit 7f11d6f

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

compiler/rustc_hir/src/lang_items.rs

+3
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ language_item_table! {
228228
AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1);
229229
AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1);
230230
AsyncFnOnce, sym::async_fn_once, async_fn_once_trait, Target::Trait, GenericRequirement::Exact(1);
231+
AsyncFnOnceOutput, sym::async_fn_once_output,async_fn_once_output, Target::AssocTy, GenericRequirement::Exact(1);
232+
CallOnceFuture, sym::call_once_future, call_once_future, Target::AssocTy, GenericRequirement::Exact(1);
233+
CallRefFuture, sym::call_ref_future, call_ref_future, Target::AssocTy, GenericRequirement::Exact(2);
231234
AsyncFnKindHelper, sym::async_fn_kind_helper,async_fn_kind_helper, Target::Trait, GenericRequirement::Exact(1);
232235

233236
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;

compiler/rustc_span/src/symbol.rs

+3
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ symbols! {
441441
async_fn_kind_helper,
442442
async_fn_mut,
443443
async_fn_once,
444+
async_fn_once_output,
444445
async_fn_track_caller,
445446
async_fn_traits,
446447
async_for_loop,
@@ -498,6 +499,8 @@ symbols! {
498499
call,
499500
call_mut,
500501
call_once,
502+
call_once_future,
503+
call_ref_future,
501504
caller_location,
502505
capture_disjoint_fields,
503506
catch_unwind,

compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,20 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
407407
output_coroutine_ty,
408408
coroutine_return_ty,
409409
}| {
410-
let (projection_term, term) = match tcx.item_name(goal.predicate.def_id()) {
411-
sym::CallOnceFuture => (
410+
let lang_items = tcx.lang_items();
411+
let (projection_term, term) = if Some(goal.predicate.def_id())
412+
== lang_items.call_once_future()
413+
{
414+
(
412415
ty::AliasTerm::new(
413416
tcx,
414417
goal.predicate.def_id(),
415418
[goal.predicate.self_ty(), tupled_inputs_ty],
416419
),
417420
output_coroutine_ty.into(),
418-
),
419-
sym::CallRefFuture => (
421+
)
422+
} else if Some(goal.predicate.def_id()) == lang_items.call_ref_future() {
423+
(
420424
ty::AliasTerm::new(
421425
tcx,
422426
goal.predicate.def_id(),
@@ -427,8 +431,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
427431
],
428432
),
429433
output_coroutine_ty.into(),
430-
),
431-
sym::Output => (
434+
)
435+
} else if Some(goal.predicate.def_id()) == lang_items.async_fn_once_output() {
436+
(
432437
ty::AliasTerm::new(
433438
tcx,
434439
goal.predicate.def_id(),
@@ -438,8 +443,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
438443
],
439444
),
440445
coroutine_return_ty.into(),
441-
),
442-
name => bug!("no such associated type: {name}"),
446+
)
447+
} else {
448+
bug!("no such associated type in `AsyncFn*`: {:?}", goal.predicate.def_id())
443449
};
444450
ty::ProjectionPredicate { projection_term, term }
445451
},

library/core/src/ops/async_function.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub trait AsyncFn<Args: Tuple>: AsyncFnMut<Args> {
2626
pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
2727
/// Future returned by [`AsyncFnMut::async_call_mut`] and [`AsyncFn::async_call`].
2828
#[unstable(feature = "async_fn_traits", issue = "none")]
29+
#[cfg_attr(not(bootstrap), lang = "call_ref_future")]
2930
type CallRefFuture<'a>: Future<Output = Self::Output>
3031
where
3132
Self: 'a;
@@ -46,10 +47,12 @@ pub trait AsyncFnMut<Args: Tuple>: AsyncFnOnce<Args> {
4647
pub trait AsyncFnOnce<Args: Tuple> {
4748
/// Future returned by [`AsyncFnOnce::async_call_once`].
4849
#[unstable(feature = "async_fn_traits", issue = "none")]
50+
#[cfg_attr(not(bootstrap), lang = "call_once_future")]
4951
type CallOnceFuture: Future<Output = Self::Output>;
5052

5153
/// Output type of the called closure's future.
5254
#[unstable(feature = "async_fn_traits", issue = "none")]
55+
#[cfg_attr(not(bootstrap), lang = "async_fn_once_output")]
5356
type Output;
5457

5558
/// Call the [`AsyncFnOnce`], returning a future which may move out of the called closure.

0 commit comments

Comments
 (0)