Structured cleanup and control flow ยท PR #4710
Run block cleanup for unlabeled break and continue
Objective
Run block cleanup for unlabeled break and continue, including tail-position forms.
Why it was needed
break and continue can leave a block before its end, but values created in that block still need Drop.
The jumps must remain inside the block’s TRY_FINALLY_EXPR body so cleanup can run.
Tail-position forms such as { break } and { continue } must also be emitted as statements. Otherwise, gccrs creates the jump but never adds it to the block.
Main changes
- Makes an unlabeled
breakreturn its lowered expression to the block instead of emitting it immediately. - Emits tail-position
breakandcontinueexpressions as statements inside the block body.
Test case
drop-unlabeled-break-continue.rs: Covers statement and tail-position forms,breakwith a value,loopandwhile, and nested cleanup order.
Current limits
Labeled
breakandcontinue, and tail-positionreturncleanup, were left for follow-up work.Issue #4717 tracks a case where
breakcomes before a local declaration in the same loop scope and the local can be dropped twice.