Skip to content

Fix explicit_counter_loop FP when the counter is only modified inside the else block of let...else binding.#17023

Open
relaxcn wants to merge 1 commit into
rust-lang:masterfrom
relaxcn:explicit_counter_loop
Open

Fix explicit_counter_loop FP when the counter is only modified inside the else block of let...else binding.#17023
relaxcn wants to merge 1 commit into
rust-lang:masterfrom
relaxcn:explicit_counter_loop

Conversation

@relaxcn
Copy link
Copy Markdown
Contributor

@relaxcn relaxcn commented May 16, 2026

Fixes: #17014

changelog: [explicit_counter_loop]: Fix FP when the counter is only modified inside the else block of let...else binding.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 16, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 16, 2026

r? @Jarcho

rustbot has assigned @Jarcho.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, llogiq, samueltardieu

Comment thread clippy_lints/src/loops/utils.rs Outdated
Comment on lines +50 to +59
if let Some(els) = l.els {
if let Some(init) = l.init {
self.visit_expr(init);
}
self.depth += 1;
self.visit_block(els);
self.depth -= 1;
} else {
walk_local(self, l);
}
Copy link
Copy Markdown
Contributor

@Jarcho Jarcho May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just be:

if let Some(init) = l.init {
  self.visit_expr(init)
  if let Some(els) = l.els {
    self.depth += 1;
    self.visit_block(els);
    self.depth -= 1;
  }
}

Note that walk_local doesn't actually do anything other than waste time.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels May 21, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 21, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@relaxcn relaxcn force-pushed the explicit_counter_loop branch from 028f495 to 22833b4 Compare May 24, 2026 14:20
@relaxcn
Copy link
Copy Markdown
Contributor Author

relaxcn commented May 24, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels May 24, 2026
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.

Lint explicit_counter_loop incorrectly triggers when incrementing in let ... else ...

3 participants