-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[else_if_without_else
]: Fix duplicate diagnostics
#12441
Conversation
if in_external_macro(cx.sess(), item.span) { | ||
return; | ||
} | ||
|
||
while let ExprKind::If(_, _, Some(ref els)) = item.kind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is to lint nested blocks (albeit weirdly?). Can you help to also add a test case for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused the lint to emit on any if-else-if-else...
chain that did not end with an else
. The lint would flag at the top of the chain, and then also flag each time EarlyLintPass::check_expr
was called on the subsequent expressions in the chain.
I added a test with 4 chains:
if bla1() {
println!("if");
} else if bla2() {
println!("else if 1");
} else if bla3() {
println!("else if 2");
} else if bla4() {
println!("else if 3");
} else if bla5() {
//~^ ERROR: `if` expression with an `else if`, but without a final `else`
println!("else if 4");
}
Before this fix, four duplicate lints are emitted for this if-else-if...
chain.
Also added a passing case four chain test, and fail/pass cases which contain suppressed [collapsible_else_if
] blocks.
30ee440
to
8d78cd1
Compare
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Relates to: #12379
changelog: Fix duplicate lint diagnostic emission from [
else_if_without_else
]