@@ -44,13 +44,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4444 let mut res = self . lower_res ( base_res) ;
4545
4646 // When we have an `async` kw on a bound, map the trait it resolves to.
47- let mut bound_modifier_allowed_features = None ;
4847 if let Some ( TraitBoundModifiers { asyncness : BoundAsyncness :: Async ( _) , .. } ) = modifiers {
4948 match res {
5049 Res :: Def ( DefKind :: Trait , def_id) => {
51- if let Some ( ( async_def_id, features ) ) = self . map_trait_to_async_trait ( def_id) {
50+ if let Some ( async_def_id) = self . map_trait_to_async_trait ( def_id) {
5251 res = Res :: Def ( DefKind :: Trait , async_def_id) ;
53- bound_modifier_allowed_features = Some ( features) ;
5452 } else {
5553 self . dcx ( ) . emit_err ( AsyncBoundOnlyForFnTraits { span : p. span } ) ;
5654 }
@@ -67,6 +65,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6765 }
6866 }
6967
68+ // Ungate the `async_fn_traits` feature in the path if the trait is
69+ // named via either `async Fn*()` or `AsyncFn*()`.
70+ let bound_modifier_allowed_features = if let Res :: Def ( DefKind :: Trait , async_def_id) = res
71+ && self . tcx . async_fn_trait_kind_from_def_id ( async_def_id) . is_some ( )
72+ {
73+ Some ( self . allow_async_fn_traits . clone ( ) )
74+ } else {
75+ None
76+ } ;
77+
7078 let path_span_lo = p. span . shrink_to_lo ( ) ;
7179 let proj_start = p. segments . len ( ) - unresolved_segments;
7280 let path = self . arena . alloc ( hir:: Path {
@@ -506,14 +514,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
506514 /// This only needs to be done until we unify `AsyncFn` and `Fn` traits into one
507515 /// that is generic over `async`ness, if that's ever possible, or modify the
508516 /// lowering of `async Fn()` bounds to desugar to another trait like `LendingFn`.
509- fn map_trait_to_async_trait ( & self , def_id : DefId ) -> Option < ( DefId , Lrc < [ Symbol ] > ) > {
517+ fn map_trait_to_async_trait ( & self , def_id : DefId ) -> Option < DefId > {
510518 let lang_items = self . tcx . lang_items ( ) ;
511519 if Some ( def_id) == lang_items. fn_trait ( ) {
512- Some ( ( lang_items. async_fn_trait ( ) ? , self . allow_async_fn_traits . clone ( ) ) )
520+ lang_items. async_fn_trait ( )
513521 } else if Some ( def_id) == lang_items. fn_mut_trait ( ) {
514- Some ( ( lang_items. async_fn_mut_trait ( ) ? , self . allow_async_fn_traits . clone ( ) ) )
522+ lang_items. async_fn_mut_trait ( )
515523 } else if Some ( def_id) == lang_items. fn_once_trait ( ) {
516- Some ( ( lang_items. async_fn_once_trait ( ) ? , self . allow_async_fn_traits . clone ( ) ) )
524+ lang_items. async_fn_once_trait ( )
517525 } else {
518526 None
519527 }
0 commit comments