← Contribution overview

Drop foundation and block scopes ยท PR #4564

Add Drop support for block-local variables

Merged

Objective

Add automatic Drop calls for supported local bindings at block exit and implicit function exit.

Why it was needed

Registering the Drop trait did not run cleanup by itself.

gccrs still did not call Drop::drop when a supported local binding reached the end of its block.

This PR added the first automatic cleanup path for simple local names.

Main changes

  • Adds tracking for block-local Drop candidates.
  • Builds a Drop call for each supported candidate when its block ends.
  • Reports unsupported Drop ref patterns and subpatterns.
  • Moves the Drop helpers into separate rust-compile-drop files.
  • Adds Drop calls at the end of function bodies for implicit returns.

Test cases

Scope of this PR

Supported bindings in this patch use simple names such as x, mut x, and _x.

ref bindings and subpatterns are not supported.

View PR on GitHub ← Contribution overview