@@ -4,11 +4,11 @@ use clippy_utils::diagnostics::span_lint_and_help;
44use  clippy_utils:: source:: snippet_opt; 
55use  clippy_utils:: ty:: is_type_diagnostic_item; 
66use  clippy_utils:: visitors:: for_each_expr; 
7- use  clippy_utils:: LimitStack ; 
7+ use  clippy_utils:: { get_async_fn_body ,  is_async_fn ,   LimitStack } ; 
88use  core:: ops:: ControlFlow ; 
99use  rustc_ast:: ast:: Attribute ; 
1010use  rustc_hir:: intravisit:: FnKind ; 
11- use  rustc_hir:: { Body ,  ExprKind ,  FnDecl ,  HirId } ; 
11+ use  rustc_hir:: { Body ,  Expr ,   ExprKind ,  FnDecl ,  HirId } ; 
1212use  rustc_lint:: { LateContext ,  LateLintPass ,  LintContext } ; 
1313use  rustc_session:: { declare_tool_lint,  impl_lint_pass} ; 
1414use  rustc_span:: source_map:: Span ; 
@@ -56,15 +56,13 @@ impl CognitiveComplexity {
5656        cx :  & LateContext < ' tcx > , 
5757        kind :  FnKind < ' tcx > , 
5858        decl :  & ' tcx  FnDecl < ' _ > , 
59-         body :  & ' tcx  Body < ' _ > , 
59+         expr :  & ' tcx  Expr < ' _ > , 
6060        body_span :  Span , 
6161    )  { 
6262        if  body_span. from_expansion ( )  { 
6363            return ; 
6464        } 
6565
66-         let  expr = body. value ; 
67- 
6866        let  mut  cc = 1u64 ; 
6967        let  mut  returns = 0u64 ; 
7068        let  _:  Option < !>  = for_each_expr ( expr,  |e| { 
@@ -146,7 +144,18 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
146144    )  { 
147145        let  def_id = cx. tcx . hir ( ) . local_def_id ( hir_id) ; 
148146        if  !cx. tcx . has_attr ( def_id. to_def_id ( ) ,  sym:: test)  { 
149-             self . check ( cx,  kind,  decl,  body,  span) ; 
147+             let  expr = if  is_async_fn ( kind)  { 
148+                 match  get_async_fn_body ( cx. tcx ,  body)  { 
149+                     Some ( b)  => b, 
150+                     None  => { 
151+                         return ; 
152+                     } , 
153+                 } 
154+             }  else  { 
155+                 body. value 
156+             } ; 
157+ 
158+             self . check ( cx,  kind,  decl,  expr,  span) ; 
150159        } 
151160    } 
152161
0 commit comments