@@ -156,29 +156,33 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
156156
157157 fn visit_fn ( & mut self , fn_kind : FnKind < ' a > , span : Span , _: NodeId ) {
158158 if let FnKind :: Fn ( _, _, sig, _, generics, body) = fn_kind {
159- if let Some (
160- CoroutineKind :: Async { closure_id, .. } | CoroutineKind :: Gen { closure_id, .. } ,
161- ) = sig. header . coroutine_kind
162- {
163- self . visit_generics ( generics) ;
164-
165- // For async functions, we need to create their inner defs inside of a
166- // closure to match their desugared representation. Besides that,
167- // we must mirror everything that `visit::walk_fn` below does.
168- self . visit_fn_header ( & sig. header ) ;
169- for param in & sig. decl . inputs {
170- self . visit_param ( param) ;
171- }
172- self . visit_fn_ret_ty ( & sig. decl . output ) ;
173- // If this async fn has no body (i.e. it's an async fn signature in a trait)
174- // then the closure_def will never be used, and we should avoid generating a
175- // def-id for it.
176- if let Some ( body) = body {
177- let closure_def =
178- self . create_def ( closure_id, kw:: Empty , DefKind :: Closure , span) ;
179- self . with_parent ( closure_def, |this| this. visit_block ( body) ) ;
159+ match sig. header . coroutine_kind {
160+ Some (
161+ CoroutineKind :: Async { closure_id, .. }
162+ | CoroutineKind :: Gen { closure_id, .. }
163+ | CoroutineKind :: AsyncGen { closure_id, .. } ,
164+ ) => {
165+ self . visit_generics ( generics) ;
166+
167+ // For async functions, we need to create their inner defs inside of a
168+ // closure to match their desugared representation. Besides that,
169+ // we must mirror everything that `visit::walk_fn` below does.
170+ self . visit_fn_header ( & sig. header ) ;
171+ for param in & sig. decl . inputs {
172+ self . visit_param ( param) ;
173+ }
174+ self . visit_fn_ret_ty ( & sig. decl . output ) ;
175+ // If this async fn has no body (i.e. it's an async fn signature in a trait)
176+ // then the closure_def will never be used, and we should avoid generating a
177+ // def-id for it.
178+ if let Some ( body) = body {
179+ let closure_def =
180+ self . create_def ( closure_id, kw:: Empty , DefKind :: Closure , span) ;
181+ self . with_parent ( closure_def, |this| this. visit_block ( body) ) ;
182+ }
183+ return ;
180184 }
181- return ;
185+ None => { }
182186 }
183187 }
184188
0 commit comments