From 3e8f53b51de543feca85af0d413376b18f598cb9 Mon Sep 17 00:00:00 2001 From: Renato Lochetti Date: Wed, 7 Jun 2023 08:35:39 +0100 Subject: [PATCH] Don't warn if there is a comment between else and curly bracket --- clippy_lints/src/formatting.rs | 6 ++++++ tests/ui/suspicious_else_formatting.rs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 4762b3543..d03480c21 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -236,6 +236,12 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) { } } + // Don't warn if the only thing inside post_else_post_eol is a comment block. + let trimmed_post_else_post_eol = post_else_post_eol.trim(); + if trimmed_post_else_post_eol.starts_with("/*") && trimmed_post_else_post_eol.ends_with("*/") { + return + } + let else_desc = if is_if(else_) { "if" } else { "{..}" }; span_lint_and_note( cx, diff --git a/tests/ui/suspicious_else_formatting.rs b/tests/ui/suspicious_else_formatting.rs index 4823d9092..a96cc1b09 100644 --- a/tests/ui/suspicious_else_formatting.rs +++ b/tests/ui/suspicious_else_formatting.rs @@ -108,6 +108,13 @@ fn main() { else { } + + //#10273 This is fine. Don't warn + if foo() { + } else + /* whelp */ + { + } } // #7650 - Don't lint. Proc-macro using bad spans for `if` expressions.