Skip to content

Conversation

@samueltardieu
Copy link
Member

@samueltardieu samueltardieu commented Jan 11, 2026

The previous tests ignored statements in a block and only looked at the final expression to determine if the block was made of a single break.

changelog: [while_let_loop]: do not ignore statements before a break when simplifying loop

Fixes #16378

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

rustbot commented Jan 11, 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

@Jarcho
Copy link
Contributor

Jarcho commented Jan 12, 2026

The lint is only wrong because the two breaks have different code before them. These two are the same:

loop {
   let Some(x) = foo() else { bar(); break; };
   baz(x);
}
while let Some(x) = foo() { baz(x); }
bar();

@samueltardieu
Copy link
Member Author

Sure, but hoisting the code before the break out of the loop would be an enhancement to this lint. This PR fixes an oversight in the lint code which causes the reported bug.

@Jarcho
Copy link
Contributor

Jarcho commented Jan 12, 2026

Can you change the test to be a case that can't lint and add a note somewhere that hoisting could be done then.

Also thank you for using black_box in the test. That should be done more.

The previous tests ignored statements in a block and only looked at the
final expression to determine if the block was made of a single `break`.
@samueltardieu
Copy link
Member Author

Can you change the test to be a case that can't lint and add a note somewhere that hoisting could be done then.

Done

Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

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

@Jarcho Jarcho enabled auto-merge January 12, 2026 12:47
@Jarcho Jarcho added this pull request to the merge queue Jan 12, 2026
Merged via the queue into rust-lang:master with commit 2a3eb6f Jan 12, 2026
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 12, 2026
@samueltardieu samueltardieu deleted the issues/16378 branch January 12, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

while_let_loop with statements false positive

3 participants