Don't warn if there is a comment between else and curly bracket

This commit is contained in:
Renato Lochetti 2023-06-07 08:35:39 +01:00
parent f729147325
commit 3e8f53b51d
No known key found for this signature in database
GPG key ID: 4B78B34B3DE7EBCC
2 changed files with 13 additions and 0 deletions

View file

@ -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,

View file

@ -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.