Different notions of "Safety" in Rust terminology

UnwindSafe is a great example of abusing the term "safety" IMO. It promises nothing you can rely on; you do not need unsafe to use AssertUnwindSafe to get something that implements the trait without changing anything else. It's just a speed-bump trying to say, apparently, "hey... think about it."

But often there's nothing to think about when it bites (catch_unwind), e.g. you have a generic closure. And so the "fix" is almost always just "slap AssertUnwindSafe on it" without thinking. Even when you are the one who might be able to observe the logic errors it's attempting to lint against, you can't even rely on std types having implementing the traits sensibly. Because these are auto-traits, that also makes it a SemVer hazard. Particular since no-one wants their erased types to look like dyn Trait + UnwindSafe + RefUnwindSafe.

There's an RFC to deprecate or downgrade it, which gets cited as a viable option in recent PRs and the like.

1 Like