error-docs icon indicating copy to clipboard operation
error-docs copied to clipboard

UnwindSafe is unrelated to `unsafe`/rust safety.

Open rustonaut opened this issue 2 years ago • 0 comments

I might be worth to more clear point out that UnwindSafe is misleading, in that it is unrelated to unsafe/rust safety guarantees.

I.e. your type must be rust-safe to reuse after a catch_unwind no matter weather it implements UnwindSafe or not. If it's not it is unsound. Something which is often missed.

UnwindSafe is more like a marker indicating that something plays well with unwinding, instead of it being "rust-safe" wrt. unwinding.

To make things worse it is relatively easy to have code which doesn't play well with unwinding, but does accidentally implement UnwindSafe due *mut T being UnwindSafe if T: RefUnwindSafe... (it is that way due to *mut T often being an owning pointer, but if it's used for a &mut T-like thing you have to explicitly remember to disable it's UnwindSafe implementation).

rustonaut avatar Nov 10 '22 01:11 rustonaut