-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Unsafe functions are confusing because they are actually robust types. Essentially, fn() is a subtype of Update<P, fn()> which is equivalent to Update<P, unsafe fn()> which is a subtype of unsafe fn(). We can see how an unsafe function taking no parameter and returning nothing is both an unsafe type of fn() and a robust type of unsafe fn().
So really when a user writes an unsafe function, they claim robustness (thus correctness). In other words, they don't have restrictions to use but permissions to use (in particular, a user may call such functions, which is otherwise not permitted if the type was just unsafe fn() and not updated).
See rust-lang/rust#151195 for context. It's very easy to think about unsafe functions as unsafe types (i.e. that have restrictions to use). But the unsafe keyword actually flips the reasoning.