@@ -4,11 +4,11 @@ use clippy_utils::diagnostics::span_lint_and_help;
4
4
use clippy_utils:: source:: snippet_opt;
5
5
use clippy_utils:: ty:: is_type_diagnostic_item;
6
6
use clippy_utils:: visitors:: for_each_expr;
7
- use clippy_utils:: LimitStack ;
7
+ use clippy_utils:: { get_async_fn_body , is_async_fn , LimitStack } ;
8
8
use core:: ops:: ControlFlow ;
9
9
use rustc_ast:: ast:: Attribute ;
10
10
use rustc_hir:: intravisit:: FnKind ;
11
- use rustc_hir:: { Body , ExprKind , FnDecl , HirId } ;
11
+ use rustc_hir:: { Body , Expr , ExprKind , FnDecl , HirId } ;
12
12
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
13
13
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
14
14
use rustc_span:: source_map:: Span ;
@@ -56,15 +56,13 @@ impl CognitiveComplexity {
56
56
cx : & LateContext < ' tcx > ,
57
57
kind : FnKind < ' tcx > ,
58
58
decl : & ' tcx FnDecl < ' _ > ,
59
- body : & ' tcx Body < ' _ > ,
59
+ expr : & ' tcx Expr < ' _ > ,
60
60
body_span : Span ,
61
61
) {
62
62
if body_span. from_expansion ( ) {
63
63
return ;
64
64
}
65
65
66
- let expr = body. value ;
67
-
68
66
let mut cc = 1u64 ;
69
67
let mut returns = 0u64 ;
70
68
let _: Option < !> = for_each_expr ( expr, |e| {
@@ -146,7 +144,18 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
146
144
) {
147
145
let def_id = cx. tcx . hir ( ) . local_def_id ( hir_id) ;
148
146
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) ;
150
159
}
151
160
}
152
161
0 commit comments