Skip to content

Commit 8a655d0

Browse files
fix: attempt to fix (not working)
1 parent 7adf0a0 commit 8a655d0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

clippy_lints/src/redundant_closure_call.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ impl<'tcx> Visitor<'tcx> for ReturnVisitor {
6161
}
6262

6363
/// Checks if the body is owned by an async closure
64-
fn is_async_closure(body: &hir::Body<'_>) -> bool {
65-
if let hir::ExprKind::Closure(_) = body.value.kind
66-
&& let Some(kind) = body.generator_kind
67-
&& kind == GeneratorKind::Async(AsyncGeneratorKind::Closure)
64+
fn is_async_closure(cx: &LateContext<'_>, body: &hir::Body<'_>) -> bool {
65+
if let hir::ExprKind::Closure(desugared_outer_closure) = body.value.kind
66+
&& let desugared_outer_closure_body = cx.tcx.hir().body(desugared_outer_closure.body)
67+
&& let hir::ExprKind::Closure(desugared_inner_closure) = desugared_outer_closure_body.value.kind
68+
// NB: `async || 42` is desugared into `|| |mut __context: #[lang = "ResumeTy"] | 42`; so
69+
// we need to check if the only input was that lang item.
70+
&& let [compiler_generated_resume_ty] = desugared_inner_closure.fn_decl.inputs
71+
&& let hir::TyKind::Path(hir::QPath::LangItem(hir::LangItem::ResumeTy, ..)) =
72+
compiler_generated_resume_ty.kind
6873
{
6974
true
7075
} else {
@@ -97,7 +102,7 @@ fn find_innermost_closure<'tcx>(
97102
&& steps > 0
98103
{
99104
expr = body.value;
100-
data = Some((body.value, closure.fn_decl, if is_async_closure(body) {
105+
data = Some((body.value, closure.fn_decl, if is_async_closure(cx, body) {
101106
hir::IsAsync::Async
102107
} else {
103108
hir::IsAsync::NotAsync

0 commit comments

Comments
 (0)