Skip to content

Commit 9ca1344

Browse files
committed
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 #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
2 parents 2360f80 + 3e8f53b commit 9ca1344

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clippy_lints/src/formatting.rs

+6
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
236236
}
237237
}
238238

239+
// Don't warn if the only thing inside post_else_post_eol is a comment block.
240+
let trimmed_post_else_post_eol = post_else_post_eol.trim();
241+
if trimmed_post_else_post_eol.starts_with("/*") && trimmed_post_else_post_eol.ends_with("*/") {
242+
return
243+
}
244+
239245
let else_desc = if is_if(else_) { "if" } else { "{..}" };
240246
span_lint_and_note(
241247
cx,

tests/ui/suspicious_else_formatting.rs

+7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ fn main() {
108108
else
109109
{
110110
}
111+
112+
//#10273 This is fine. Don't warn
113+
if foo() {
114+
} else
115+
/* whelp */
116+
{
117+
}
111118
}
112119

113120
// #7650 - Don't lint. Proc-macro using bad spans for `if` expressions.

0 commit comments

Comments
 (0)