Structured cleanup and control flow ยท PR #4685
Emit block-scope Drops through TRY_FINALLY_EXPR
Objective
Emit block-scope Drop calls through a TRY_FINALLY_EXPR cleanup.
Why it was needed
gccrs used to append Drop calls to the end of a block. With that design, an early exit such as return, break, or continue would need separate cleanup logic.
TRY_FINALLY_EXPR keeps the block body and its Drop calls in one GCC tree structure. Later control-flow work can reuse that cleanup path.
Main changes
- Builds the Drop calls for one scope as one statement tree.
- Wraps the block body in
TRY_FINALLY_EXPRonly when cleanup exists. - Uses
EH_ELSE_EXPRto place the Drop calls in the normal cleanup arm and an empty statement in the exceptional arm.
Test case
drop-nested-block-scope.rs: An existing test for nested scopes and reverse Drop order. It linked and passed locally after theEH_ELSE_EXPRchange.