The documentation for the UnwindSafe
trait hints at a reason for this:
Who implements UnwindSafe?
Types such as &mut T and &RefCell are examples which are not unwind safe. The general idea is that any mutable state which can be shared across catch_unwind is not unwind safe by default. This is because it is very easy to witness a broken invariant outside of catch_unwind as the data is simply accessed as usual.
Types like &Mutex, however, are unwind safe because they implement poisoning by default. They still allow witnessing a broken invariant, but they already provide their own “speed bumps” to do so.
futures::lock::Mutex
provides mutability like &mut T
and RefCell<T>
, but does not implement the poisoning feature of std::sync::Mutex<T>
, so it does not implement UnwindSafe
.
Though as the documentation points out, the UnwindSafe
is less about memory safety and more about upholding logical invariants - hence why neither UnwindSafe
nor AssertUnwindSafe
are unsafe
.