Skip to content

Commit a49ea2d

Browse files
fix: unnecessary_lazy_evaluations suggests wrongly for async closure (#14644)
Closes rust-lang/rust-clippy#14578 changelog: [`unnecessary_lazy_evaluations`] fix wrong suggestions for async closure
2 parents ac88357 + 5a1dbea commit a49ea2d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

clippy_lints/src/methods/unnecessary_lazy_eval.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ pub(super) fn check<'tcx>(
2424
let is_bool = cx.typeck_results().expr_ty(recv).is_bool();
2525

2626
if (is_option || is_result || is_bool)
27-
&& let hir::ExprKind::Closure(&hir::Closure { body, fn_decl, .. }) = arg.kind
27+
&& let hir::ExprKind::Closure(&hir::Closure {
28+
body,
29+
fn_decl,
30+
kind: hir::ClosureKind::Closure,
31+
..
32+
}) = arg.kind
2833
{
2934
let body = cx.tcx.hir_body(body);
3035
let body_expr = &body.value;

tests/ui/unnecessary_lazy_eval.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,7 @@ fn panicky_arithmetic_ops(x: usize, y: isize) {
321321
let _x = false.then_some(f1 + f2);
322322
//~^ unnecessary_lazy_evaluations
323323
}
324+
325+
fn issue14578() {
326+
let _: Box<dyn std::future::Future<Output = i32>> = Box::new(true.then(async || 42).unwrap());
327+
}

tests/ui/unnecessary_lazy_eval.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,7 @@ fn panicky_arithmetic_ops(x: usize, y: isize) {
321321
let _x = false.then(|| f1 + f2);
322322
//~^ unnecessary_lazy_evaluations
323323
}
324+
325+
fn issue14578() {
326+
let _: Box<dyn std::future::Future<Output = i32>> = Box::new(true.then(async || 42).unwrap());
327+
}

0 commit comments

Comments
 (0)