@@ -746,15 +746,17 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
746
746
function_kind : FnKind < ' tcx > ,
747
747
declaration : & ' tcx FnDecl ,
748
748
_: Span ,
749
- node_id : NodeId ) {
750
- let rib_kind = match function_kind {
751
- FnKind :: ItemFn ( ..) => {
752
- ItemRibKind
753
- }
754
- FnKind :: Method ( _, _, _, _) => {
755
- TraitOrImplItemRibKind
756
- }
757
- FnKind :: Closure ( _) => ClosureRibKind ( node_id) ,
749
+ node_id : NodeId )
750
+ {
751
+ let ( rib_kind, asyncness) = match function_kind {
752
+ FnKind :: ItemFn ( _, ref header, ..) =>
753
+ ( ItemRibKind , header. asyncness ) ,
754
+ FnKind :: Method ( _, ref sig, _, _) =>
755
+ ( TraitOrImplItemRibKind , sig. header . asyncness ) ,
756
+ FnKind :: Closure ( _) =>
757
+ // Async closures aren't resolved through `visit_fn`-- they're
758
+ // processed separately
759
+ ( ClosureRibKind ( node_id) , IsAsync :: NotAsync ) ,
758
760
} ;
759
761
760
762
// Create a value rib for the function.
@@ -774,7 +776,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
774
776
}
775
777
visit:: walk_fn_ret_ty ( self , & declaration. output ) ;
776
778
777
- // Resolve the function body.
779
+ // Resolve the function body, potentially inside the body of an async closure
780
+ if let IsAsync :: Async ( async_closure_id) = asyncness {
781
+ let rib_kind = ClosureRibKind ( async_closure_id) ;
782
+ self . ribs [ ValueNS ] . push ( Rib :: new ( rib_kind) ) ;
783
+ self . label_ribs . push ( Rib :: new ( rib_kind) ) ;
784
+ }
785
+
778
786
match function_kind {
779
787
FnKind :: ItemFn ( .., body) |
780
788
FnKind :: Method ( .., body) => {
@@ -785,6 +793,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> {
785
793
}
786
794
} ;
787
795
796
+ // Leave the body of the async closure
797
+ if asyncness. is_async ( ) {
798
+ self . label_ribs . pop ( ) ;
799
+ self . ribs [ ValueNS ] . pop ( ) ;
800
+ }
801
+
788
802
debug ! ( "(resolving function) leaving function" ) ;
789
803
790
804
self . label_ribs . pop ( ) ;
@@ -2054,47 +2068,6 @@ impl<'a> Resolver<'a> {
2054
2068
self . check_proc_macro_attrs ( & item. attrs ) ;
2055
2069
2056
2070
match item. node {
2057
- ItemKind :: Fn ( ref declaration,
2058
- FnHeader { asyncness : IsAsync :: Async ( async_closure_id) , .. } ,
2059
- ref generics,
2060
- ref body) => {
2061
- // Async functions are desugared from `async fn foo() { .. }`
2062
- // to `fn foo() { future_from_generator(move || ... ) }`,
2063
- // so we have to visit the body inside the closure scope
2064
- self . with_type_parameter_rib ( HasTypeParameters ( generics, ItemRibKind ) , |this| {
2065
- this. visit_vis ( & item. vis ) ;
2066
- this. visit_ident ( item. ident ) ;
2067
- this. visit_generics ( generics) ;
2068
- let rib_kind = ItemRibKind ;
2069
- this. ribs [ ValueNS ] . push ( Rib :: new ( rib_kind) ) ;
2070
- this. label_ribs . push ( Rib :: new ( rib_kind) ) ;
2071
- let mut bindings_list = FxHashMap ( ) ;
2072
- for argument in & declaration. inputs {
2073
- this. resolve_pattern (
2074
- & argument. pat , PatternSource :: FnParam , & mut bindings_list) ;
2075
- this. visit_ty ( & * argument. ty ) ;
2076
- }
2077
- visit:: walk_fn_ret_ty ( this, & declaration. output ) ;
2078
-
2079
- // Now resolve the inner closure
2080
- {
2081
- let rib_kind = ClosureRibKind ( async_closure_id) ;
2082
- this. ribs [ ValueNS ] . push ( Rib :: new ( rib_kind) ) ;
2083
- this. label_ribs . push ( Rib :: new ( rib_kind) ) ;
2084
- // No need to resolve either arguments nor return type,
2085
- // as this closure has neither
2086
-
2087
- // Resolve the body
2088
- this. visit_block ( body) ;
2089
- this. label_ribs . pop ( ) ;
2090
- this. ribs [ ValueNS ] . pop ( ) ;
2091
- }
2092
- this. label_ribs . pop ( ) ;
2093
- this. ribs [ ValueNS ] . pop ( ) ;
2094
-
2095
- walk_list ! ( this, visit_attribute, & item. attrs) ;
2096
- } )
2097
- }
2098
2071
ItemKind :: Enum ( _, ref generics) |
2099
2072
ItemKind :: Ty ( _, ref generics) |
2100
2073
ItemKind :: Struct ( _, ref generics) |
@@ -2415,7 +2388,7 @@ impl<'a> Resolver<'a> {
2415
2388
visit:: walk_impl_item ( this, impl_item)
2416
2389
) ;
2417
2390
}
2418
- ImplItemKind :: Method ( _ , _ ) => {
2391
+ ImplItemKind :: Method ( .. ) => {
2419
2392
// If this is a trait impl, ensure the method
2420
2393
// exists in trait
2421
2394
this. check_trait_item ( impl_item. ident ,
0 commit comments