about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-06-08 04:18:08 +0000
committerbors <bors@rust-lang.org>2023-06-08 04:18:08 +0000
commit9ca1344d9ad5724fcac3e29b9d6fa084f3e59f52 (patch)
tree5548f08b24a729e4153e4c3cb5a2e23681bd996f
parent2360f801432d3ecd8744164332b519e43f35fe96 (diff)
parent3e8f53b51de543feca85af0d413376b18f598cb9 (diff)
downloadrust-9ca1344d9ad5724fcac3e29b9d6fa084f3e59f52.tar.gz
rust-9ca1344d9ad5724fcac3e29b9d6fa084f3e59f52.zip
Auto merge of #10904 - lochetti:fix_10273, r=Centri3
`suspicious_else_formatting`: Don't warn if there is a comment between else and curly bracket

This PR fixes https://github.com/rust-lang/rust-clippy/issues/10273

The idea is that if the only thing after `else` and before `{` is a comment, we will not warn because, probably, the line break was "made" by rustfmt.

changelog: [`suspicious_else_formatting`]: Don't warn if the only thing between `else` and curly bracket is a comment
-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.