GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

gccrs: Emit block scope drops through TRY_FINALLY_EXPR

GCC's Rust compiler now emits block scope drops using TRY_FINALLY_EXPR for proper cleanup.

GCC’s Rust compiler has been updated to emit block-scope Drop calls through TRY_FINALLY_EXPR. This change ensures that destructors are correctly invoked when blocks are exited, even if cleanup code is involved. A new function, Context::pop_block_with_cleanup, is introduced to facilitate this, allowing cleanup logic to be passed as part of the block-popping operation.

In Details

The gccrs backend now uses TRY_FINALLY_EXPR to manage cleanup for blocks that require a Drop. When a block is exited, if it contains code that needs to be run for cleanup (e.g., due to variables with Drop implementations going out of scope), this cleanup code is now wrapped in a TRY_FINALLY_EXPR. This integrates better with GCC's generic exception handling machinery and ensures that Drop glue is emitted correctly.

For Context
Drop
In Rust, a trait that can be implemented for a type to define custom logic that runs when a value of that type goes out of scope. This is primarily used for resource management.
TRY_FINALLY_EXPR
An expression that guarantees a 'finally' block is executed, regardless of whether the 'try' block completes normally or exits via an exception or other control flow transfer.
block scope
The region of code within curly braces {} where variables declared are accessible. When the block ends, these variables are dropped.
Filed Under: gccrscleanupcompiler