In this reddit post I asked what might cause corruption if
std::rt::unwind::try is being nested. At the end of the discussion I was advised to post my question here.
So can corruption occur in the recent versions rustc if
std::rt::unwind::try is being nested? If it can, under what circumstances it happens and can it be fixed without much hassle? If it cannot, shouldn’t someone update the docs?
We also discussed the unsafety of the function. Reddit user riccieri explained that even if no corruption occurs, the panic in the closure can leave some objects in inconsistent state. A similar argument was being made for
Thread::scoped and that’s why it propagates panics in the recent versions.
But if the closure passed to
'static (most of) the inconsistent objects cannot be reached. Reddit user wrongerontheinternet even proposed adding a poison bit to
RefCell, so if there are no unsafe sections no object affected by the panicking environment is reachable after the return of
So to refine my second question:
Assuming it is safe to nest
std::rt::unwind::try, can we make a safe function with similar semantics with the above-mentioned suggestions?