mirror of
https://github.com/horizon-rust/horizon-mixins.git
synced 2026-12-03 19:34:02 +07:00
[PR #9] [MERGED] RETURN: allow references to calls and closures outside exit values #14
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
horizon-rust/horizon-mixins#14
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/horizon-rust/horizon-mixins/pull/9
Author: @levzzz5154
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154
Base:
main← Head:feat/return-hooks-temporaries📝 Commits (2)
9a6f6daRETURN: allow references to calls and closures outside exit values01160a9RETURN: a closure's own return is not an exit; closure locals keep out of ordinals📊 Changes
7 files changed (+288 additions, -20 deletions)
View changed files
📝
README.md(+4 -3)➕
crates/horizon-mixins-cli/tests/cases/returns.rs(+170 -0)📝
crates/horizon-mixins-cli/tests/integration.rs(+3 -0)📝
crates/horizon-mixins-core/src/plan.rs(+67 -11)📝
crates/horizon-mixins-core/src/scopes.rs(+20 -3)📝
docs/advanced-injections.md(+20 -2)📝
docs/mixin-api.md(+4 -1)📄 Description
Closes #6.
What and why
A RETURN hook on Horizon's
Game::picked_stackwas refused withE_UNSUPPORTED_CONTROL_FLOW("calls beneath a reference may change temporary lifetimes") because ofdecode_components(Some(&Tag::Compound(all)))in a statement. Once that passes, the same target is refused again for the closures in itsif letcondition (.filter(|s| ...),.and_then(|s| ...)); the validator only reports the last error, so the issue saw one of the two.Both checks run over the whole body for every hook kind except HEAD. RETURN only rewrites the exit values: each
returnoperand and the function tail become a helper call argument,({ fn helper.. helper })(value). Nothing else in the body changes, so:ReturnRewritealready skips closures, and areturninside one leaves the closure, not the target;always_exitsnever counts a closure as an exit).So for RETURN:
exit_value_error), so the moved value never contains them;?, async,await, unsafe and const are still refused everywhere, including inside closures (the visitor still descends into them);Checks
cargo fmt --all --checkcargo clippy --workspace --all-targets --locked -- -D warningscargo test --workspace --locked: 92 passed. Newtests/cases/returns.rs:let-extended reference, closures (one with its ownreturn), an early return and a tail. It checks the hook runs on both exits and the drop order is unchanged (argument,body,helper,extended). Without the fix it is refused.?and async inside a closure, and a BEFORE_CALL on the same body.main(exported withgit archive): a RETURN mod onhorizon_client::game::block_items::Game<'_>::picked_stackplans and applies, and the stage passescargo check -p horizon-client.Follow-up (review)
returnis no longer a RETURN capture context, andlets inside closures no longer shift capture ordinals ($local_ref:later:0is the function's own firstlater). Neither case was reachable before this PR, since RETURN refused closures. New testreturn_hooks_capture_locals_past_closures_with_their_own_returns_and_lets, which fails withE_LOCAL_NOT_VISIBLEwithout the fix.returnand checks that the helper runs once per call.docs/mixin-api.md,README.mdand the RETURN paragraph no longer describe the old restriction. 93 tests pass.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.