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
This commit is contained in:
Samuel Tardieu 2025-04-17 14:42:15 +00:00 committed by GitHub
commit a49ea2d63d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 1 deletions

View file

@ -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;

View file

@ -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());
}

View file

@ -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());
}