about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-04-17 14:42:15 +0000
committerGitHub <noreply@github.com>2025-04-17 14:42:15 +0000
commita49ea2d63d03e485eaf5fa1b7dcdbaca162427c7 (patch)
tree5df8ef36e55634c0a9e96fedf0f69e45c2c769fa
parentac88357f83ddc9efb3b05032ed822d18d0fd38f9 (diff)
parent5a1dbea052abee0326e0878beae671fbbf19cbe1 (diff)
downloadrust-a49ea2d63d03e485eaf5fa1b7dcdbaca162427c7.tar.gz
rust-a49ea2d63d03e485eaf5fa1b7dcdbaca162427c7.zip
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
-rw-r--r--clippy_lints/src/methods/unnecessary_lazy_eval.rs7
-rw-r--r--tests/ui/unnecessary_lazy_eval.fixed4
-rw-r--r--tests/ui/unnecessary_lazy_eval.rs4
3 files changed, 14 insertions, 1 deletions
diff --git a/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/clippy_lints/src/methods/unnecessary_lazy_eval.rs
index e3596cf6a60..71e606add52 100644
--- a/clippy_lints/src/methods/unnecessary_lazy_eval.rs
+++ b/clippy_lints/src/methods/unnecessary_lazy_eval.rs
@@ -24,7 +24,12 @@ pub(super) fn check<'tcx>(
     let is_bool = cx.typeck_results().expr_ty(recv).is_bool();
 
     if (is_option || is_result || is_bool)
-        && let hir::ExprKind::Closure(&hir::Closure { body, fn_decl, .. }) = arg.kind
+        && let hir::ExprKind::Closure(&hir::Closure {
+            body,
+            fn_decl,
+            kind: hir::ClosureKind::Closure,
+            ..
+        }) = arg.kind
     {
         let body = cx.tcx.hir_body(body);
         let body_expr = &body.value;
diff --git a/tests/ui/unnecessary_lazy_eval.fixed b/tests/ui/unnecessary_lazy_eval.fixed
index 9a329081638..409a8efbfeb 100644
--- a/tests/ui/unnecessary_lazy_eval.fixed
+++ b/tests/ui/unnecessary_lazy_eval.fixed
@@ -321,3 +321,7 @@ fn panicky_arithmetic_ops(x: usize, y: isize) {
     let _x = false.then_some(f1 + f2);
     //~^ unnecessary_lazy_evaluations
 }
+
+fn issue14578() {
+    let _: Box<dyn std::future::Future<Output = i32>> = Box::new(true.then(async || 42).unwrap());
+}
diff --git a/tests/ui/unnecessary_lazy_eval.rs b/tests/ui/unnecessary_lazy_eval.rs
index 2d05ef5c291..54735023a93 100644
--- a/tests/ui/unnecessary_lazy_eval.rs
+++ b/tests/ui/unnecessary_lazy_eval.rs
@@ -321,3 +321,7 @@ fn panicky_arithmetic_ops(x: usize, y: isize) {
     let _x = false.then(|| f1 + f2);
     //~^ unnecessary_lazy_evaluations
 }
+
+fn issue14578() {
+    let _: Box<dyn std::future::Future<Output = i32>> = Box::new(true.then(async || 42).unwrap());
+}