Surprising/"exciting" behaviour of inner move closures

Where this would potentially cause issues is interacting with @Soni's other proposal, Closure ergonomics/movable whole bindings, where "move closuring" a binding removes it from scope and reëxposes any binding that it shadowed.

(This is effectively in the wrong thread but) this is why it's important that this isn't the case. Your motivating examples all have the shadowing binding directly before the move closure that removes it, but a) it's an implicit whether a binding gets moved, and b) any binding, no matter how lexically far it is from the closure, can be moved.

This is the reason we have the borrow checker in the first place. It's too onerous to expect the programmer to track exactly where bindings are borrowed and moved, so the borrow checker exists to make sure that what you've written makes sense. If moving a binding reëxposes the shadowed binding, then while it's not a use-after-move, you're still using a binding different from the one you expected to use, which is a change in program semantics from what the programmer thought and what the machine understood.

1 Like