Skip to content

Resolve infinite_loop FP for nested loops#16724

Open
mikhailofff wants to merge 1 commit intorust-lang:masterfrom
mikhailofff:fix/issue-16134
Open

Resolve infinite_loop FP for nested loops#16724
mikhailofff wants to merge 1 commit intorust-lang:masterfrom
mikhailofff:fix/issue-16134

Conversation

@mikhailofff
Copy link
Copy Markdown
Contributor

@mikhailofff mikhailofff commented Mar 17, 2026

Fixes #16134.

changelog: [infinite_loop]: look thoroughly the case when there are nested loops that cannot be infinite, because there is a break statement that interrupts another loop that takes up space above.

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

rustbot commented Mar 17, 2026

r? @samueltardieu

rustbot has assigned @samueltardieu.
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, dswij, llogiq, samueltardieu

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Mar 17, 2026
@rustbot

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Mar 17, 2026
@rustbot

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 17, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Copy Markdown
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

break and continue have a field of type Destination which contains the HirId of the target of the break or continue. Can't you use that instead of labels to match the various blocks and loops that can be the target of the break?

@rustbot author

View changes since this review

@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 Mar 21, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 21, 2026

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

}| {
if let ExprKind::Break(hir::Destination { label: _, target_id }, ..) = kind
&& let Ok(t_id) = target_id
&& t_id.local_id < self.ex.hir_id.local_id
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.

Thanks for the review. I actually had this in mind. The use of potential_breaks in LoopVisitor is necessary to store the break statements that may terminate the original loop if it points to a loop that precedes the original loop. If the target_id only points to the loop that will actually be terminated by the break, then everything is fine. I hope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

infinite-loop and never_loop trigger on the same loop 😆

3 participants