Closed edef1c closed 7 years ago
An additional complication with panicking is that this turns any panic that drops the generator into a panic-in-panic, and we can't find out whether we're currently unwinding without help from the platform library (eg std::thread::panicking
).
@Amanieu raised a rather important concern: leaking the Stack
impl doesn't do us any good if it doesn't own the underlying memory (ie if it isn't 'static
)
For example, if we have a SliceStack
using an array on the parent's stack, returning or panicking will free it even if we leak the SliceStack
value we hold.
Either we have to restrict ourselves to Stack + 'static
or we have to ensure unwinding.
I should probably document the guarantee unsafe_new
expects you to provide but I'll have to work on wording for that.
We can't free the stack before the generator has returned, or been unwound. Without unwinding, the only safe course of action is to leak it.
We could additionally panic, since users can
mem::forget
the generator if they do intend to leak. Leaking in the destructor is not avoidable even if we panic, since we can't free the stack.