From f7ab51af2a2a893c45f66ae6299c8621db6b9646 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 16 Jul 2025 06:57:22 +0000 Subject: [PATCH] Early abort for unused braces check in closure bodies --- compiler/rustc_lint/src/unused.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index a9eb1739f7f10..fca823c01cb32 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1483,7 +1483,11 @@ impl UnusedDelimLint for UnusedBraces { ) { match value.kind { ast::ExprKind::Block(ref inner, None) - if inner.rules == ast::BlockCheckMode::Default => + if inner.rules == ast::BlockCheckMode::Default + && ctx != UnusedDelimsCtx::ClosureBody + && value.attrs.is_empty() + && !value.span.from_expansion() + && !inner.span.from_expansion() => { // emit a warning under the following conditions: // @@ -1515,11 +1519,7 @@ impl UnusedDelimLint for UnusedBraces { && (ctx != UnusedDelimsCtx::AnonConst || (matches!(expr.kind, ast::ExprKind::Lit(_)) && !expr.span.from_expansion())) - && ctx != UnusedDelimsCtx::ClosureBody && !cx.sess().source_map().is_multiline(value.span) - && value.attrs.is_empty() - && !value.span.from_expansion() - && !inner.span.from_expansion() { self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw) }