Function exits and return values ยท PR #4602
Evaluate non-unit tail expressions before Drops
Objective
Evaluate a non-unit tail expression before local Drop calls.
Save the result, run cleanup, and then return the saved value.
Why it was needed
A non-unit tail expression supplies the function’s return value. It must run before local variables are dropped.
The old lowering ran cleanup first, so a tail call could happen too late.
This PR saves the value before cleanup and returns it afterward.
Main changes
- Stores the tail-expression result in the function return slot before emitting Drop calls.
- Runs the local Drop calls.
- Returns the saved value from the function return slot after the Drop calls.
Test case
- drop-function-scope-non-unit-tail.rs: Expected output
fthendchecks that the tail call runs before the local Drop.