@@ -280,15 +280,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
280280 callee_node : & hir:: ExprKind < ' _ > ,
281281 callee_span : Span ,
282282 ) {
283- let hir_id = self . tcx . hir ( ) . get_parent_node ( hir_id) ;
284- let parent_node = self . tcx . hir ( ) . get ( hir_id) ;
283+ let hir = self . tcx . hir ( ) ;
284+ let parent_hir_id = hir. get_parent_node ( hir_id) ;
285+ let parent_node = hir. get ( parent_hir_id) ;
285286 if let (
286287 hir:: Node :: Expr ( hir:: Expr {
287- kind : hir:: ExprKind :: Closure { fn_decl_span, .. } , ..
288+ kind : hir:: ExprKind :: Closure { fn_decl_span, body, .. } ,
289+ ..
288290 } ) ,
289291 hir:: ExprKind :: Block ( ..) ,
290292 ) = ( parent_node, callee_node)
291293 {
294+ let fn_decl_span = if hir. body ( * body) . generator_kind
295+ == Some ( hir:: GeneratorKind :: Async ( hir:: AsyncGeneratorKind :: Closure ) )
296+ {
297+ // Actually need to unwrap a few more layers of HIR to get to
298+ // the _real_ closure...
299+ let async_closure = hir. get_parent_node ( hir. get_parent_node ( parent_hir_id) ) ;
300+ if let hir:: Node :: Expr ( hir:: Expr {
301+ kind : hir:: ExprKind :: Closure { fn_decl_span, .. } ,
302+ ..
303+ } ) = hir. get ( async_closure)
304+ {
305+ * fn_decl_span
306+ } else {
307+ return ;
308+ }
309+ } else {
310+ * fn_decl_span
311+ } ;
312+
292313 let start = fn_decl_span. shrink_to_lo ( ) ;
293314 let end = callee_span. shrink_to_hi ( ) ;
294315 err. multipart_suggestion (
0 commit comments