about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRenato Lochetti <renato.lochetti@gmail.com>2023-06-07 08:35:39 +0100
committerRenato Lochetti <renato.lochetti@gmail.com>2023-06-07 09:42:37 +0100
commit3e8f53b51de543feca85af0d413376b18f598cb9 (patch)
treedb91d0b8330df00767ffd58cbd0ef88b9b106468
parentf72914732527904480887847fe2c20df42e24dc2 (diff)
downloadrust-3e8f53b51de543feca85af0d413376b18f598cb9.tar.gz
rust-3e8f53b51de543feca85af0d413376b18f598cb9.zip
Don't warn if there is a comment between else and curly bracket
-rw-r--r--clippy_lints/src/formatting.rs6
-rw-r--r--tests/ui/suspicious_else_formatting.rs7
2 files changed, 13 insertions, 0 deletions
diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs
index 4762b354392..d03480c2108 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 4823d909208..a96cc1b090c 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.