Skip to content

Commit bb326e7

Browse files
committed
Auto merge of rust-lang#9836 - koka831:patch-9300, r=Alexendoo
Fix is_async_fn to check FnKind::Method This is a follow-up PR of rust-lang/rust-clippy#9828 to support also async methods. changelog: [`cognitive_complexity`] support async method r? `@Alexendoo`
2 parents 755fe4d + 34c4520 commit bb326e7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

clippy_utils/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,11 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>,
19011901

19021902
/// Checks if the given function kind is an async function.
19031903
pub fn is_async_fn(kind: FnKind<'_>) -> bool {
1904-
matches!(kind, FnKind::ItemFn(_, _, header) if header.asyncness == IsAsync::Async)
1904+
match kind {
1905+
FnKind::ItemFn(_, _, header) => header.asyncness == IsAsync::Async,
1906+
FnKind::Method(_, sig) => sig.header.asyncness == IsAsync::Async,
1907+
FnKind::Closure => false,
1908+
}
19051909
}
19061910

19071911
/// Peels away all the compiler generated code surrounding the body of an async function,

tests/ui/cognitive_complexity.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,12 @@ mod issue9300 {
400400
let a = 0;
401401
if a == 0 {}
402402
}
403+
404+
pub struct S;
405+
impl S {
406+
pub async fn async_method() {
407+
let a = 0;
408+
if a == 0 {}
409+
}
410+
}
403411
}

tests/ui/cognitive_complexity.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,13 @@ LL | async fn a() {
143143
|
144144
= help: you could split it up into multiple smaller functions
145145

146-
error: aborting due to 18 previous errors
146+
error: the function has a cognitive complexity of (2/1)
147+
--> $DIR/cognitive_complexity.rs:406:22
148+
|
149+
LL | pub async fn async_method() {
150+
| ^^^^^^^^^^^^
151+
|
152+
= help: you could split it up into multiple smaller functions
153+
154+
error: aborting due to 19 previous errors
147155

0 commit comments

Comments
 (0)