← Contribution overview

Structured cleanup and control flow ยท PR #4685

Emit block-scope Drops through TRY_FINALLY_EXPR

Merged

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_EXPR only when cleanup exists.
  • Uses EH_ELSE_EXPR to 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 the EH_ELSE_EXPR change.
View PR on GitHub ← Contribution overview