@@ -44,13 +44,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
44
44
let mut res = self . lower_res ( base_res) ;
45
45
46
46
// When we have an `async` kw on a bound, map the trait it resolves to.
47
- let mut bound_modifier_allowed_features = None ;
48
47
if let Some ( TraitBoundModifiers { asyncness : BoundAsyncness :: Async ( _) , .. } ) = modifiers {
49
48
match res {
50
49
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) {
52
51
res = Res :: Def ( DefKind :: Trait , async_def_id) ;
53
- bound_modifier_allowed_features = Some ( features) ;
54
52
} else {
55
53
self . dcx ( ) . emit_err ( AsyncBoundOnlyForFnTraits { span : p. span } ) ;
56
54
}
@@ -67,6 +65,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
67
65
}
68
66
}
69
67
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
+
70
78
let path_span_lo = p. span . shrink_to_lo ( ) ;
71
79
let proj_start = p. segments . len ( ) - unresolved_segments;
72
80
let path = self . arena . alloc ( hir:: Path {
@@ -506,14 +514,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
506
514
/// This only needs to be done until we unify `AsyncFn` and `Fn` traits into one
507
515
/// that is generic over `async`ness, if that's ever possible, or modify the
508
516
/// 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 > {
510
518
let lang_items = self . tcx . lang_items ( ) ;
511
519
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 ( )
513
521
} 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 ( )
515
523
} 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 ( )
517
525
} else {
518
526
None
519
527
}
0 commit comments