Function exits and return values ยท PR #4591
Support function-scope Drops on normal function exit
Objective
Add function-scope Drop handling for normal exits.
Cover unit tail expressions and function parameters.
Why it was needed
A function can end with a tail expression of type (). A call to another unit-returning function is one example.
gccrs did not emit local Drop calls after this form, and it did not register droppable parameters.
This PR added both cases to normal function-exit cleanup.
Main changes
- Emits the current scope’s Drop calls after compiling a unit tail expression.
- Collects droppable parameters while compiling the parameter list, then registers them after creating the function-body block.
- This registration order makes body locals drop before parameters on a normal function exit.
Test cases
- drop-function-scope-unit-tail.rs: Runs one function with a unit call and one with
()as the tail expression; both locals are dropped. - drop-function-params.rs: Covers named and wildcard parameters. The expected output checks that each body local drops before its parameter.
Later change
At this point, parameters and body locals still shared one Drop-candidate list.
PR #4718 later separated their scopes.