Skip to content
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

Merged
merged 1 commit into from
Mar 16, 2024

Conversation

CBSpeir
Copy link
Contributor

@CBSpeir CBSpeir commented Mar 9, 2024

Relates to: #12379

changelog: Fix duplicate lint diagnostic emission from [else_if_without_else]

@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2024

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 9, 2024
if in_external_macro(cx.sess(), item.span) {
return;
}

while let ExprKind::If(_, _, Some(ref els)) = item.kind {
Copy link
Member

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?

Copy link
Contributor Author

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.

@CBSpeir CBSpeir force-pushed the dedup-else-if-without-else branch from 30ee440 to 8d78cd1 Compare March 9, 2024 04:38
@dswij
Copy link
Member

dswij commented Mar 16, 2024

Thank you! @bors r+

@bors
Copy link
Contributor

bors commented Mar 16, 2024

📌 Commit 8d78cd1 has been approved by dswij

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 16, 2024

⌛ Testing commit 8d78cd1 with merge 59a5ad4...

@bors
Copy link
Contributor

bors commented Mar 16, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: dswij
Pushing 59a5ad4 to master...

@bors bors merged commit 59a5ad4 into rust-lang:master Mar 16, 2024
5 checks passed
@CBSpeir CBSpeir deleted the dedup-else-if-without-else branch March 16, 2024 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants