Skip to content

Commit 3c93ba0

Browse files
authored
is_async_fn: use FnKind::asyncness (#15772)
changelog: none
2 parents 3e218d1 + 6b4febe commit 3c93ba0

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

clippy_lints/src/cognitive_complexity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
33
use clippy_utils::source::{IntoSpan, SpanRangeExt};
44
use clippy_utils::ty::is_type_diagnostic_item;
55
use clippy_utils::visitors::for_each_expr_without_closures;
6-
use clippy_utils::{LimitStack, get_async_fn_body, is_async_fn, sym};
6+
use clippy_utils::{LimitStack, get_async_fn_body, sym};
77
use core::ops::ControlFlow;
88
use rustc_hir::intravisit::FnKind;
99
use rustc_hir::{Attribute, Body, Expr, ExprKind, FnDecl};
@@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
147147
def_id: LocalDefId,
148148
) {
149149
if !cx.tcx.has_attr(def_id, sym::test) {
150-
let expr = if is_async_fn(kind) {
150+
let expr = if kind.asyncness().is_async() {
151151
match get_async_fn_body(cx.tcx, body) {
152152
Some(b) => b,
153153
None => {

clippy_lints/src/implicit_return.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_hir_and_then;
22
use clippy_utils::source::{snippet_with_applicability, snippet_with_context, walk_span_to_context};
33
use clippy_utils::visitors::for_each_expr_without_closures;
4-
use clippy_utils::{desugar_await, get_async_closure_expr, get_async_fn_body, is_async_fn, is_from_proc_macro};
4+
use clippy_utils::{desugar_await, get_async_closure_expr, get_async_fn_body, is_from_proc_macro};
55
use core::ops::ControlFlow;
66
use rustc_errors::Applicability;
77
use rustc_hir::intravisit::FnKind;
@@ -240,7 +240,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
240240
return;
241241
}
242242

243-
let expr = if is_async_fn(kind) {
243+
let expr = if kind.asyncness().is_async() {
244244
match get_async_fn_body(cx.tcx, body) {
245245
Some(e) => e,
246246
None => return,

clippy_utils/src/lib.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ use rustc_hir::def::{DefKind, Res};
9898
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
9999
use rustc_hir::definitions::{DefPath, DefPathData};
100100
use rustc_hir::hir_id::{HirIdMap, HirIdSet};
101-
use rustc_hir::intravisit::{FnKind, Visitor, walk_expr};
101+
use rustc_hir::intravisit::{Visitor, walk_expr};
102102
use rustc_hir::{
103103
self as hir, Arm, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind, CoroutineDesugaring,
104104
CoroutineKind, CoroutineSource, Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArg, GenericArgs,
@@ -1854,15 +1854,6 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>,
18541854
(conds, blocks)
18551855
}
18561856

1857-
/// Checks if the given function kind is an async function.
1858-
pub fn is_async_fn(kind: FnKind<'_>) -> bool {
1859-
match kind {
1860-
FnKind::ItemFn(_, _, header) => header.asyncness.is_async(),
1861-
FnKind::Method(_, sig) => sig.header.asyncness.is_async(),
1862-
FnKind::Closure => false,
1863-
}
1864-
}
1865-
18661857
/// Peels away all the compiler generated code surrounding the body of an async closure.
18671858
pub fn get_async_closure_expr<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
18681859
if let ExprKind::Closure(&Closure {

0 commit comments

Comments
 (0)