This is already how it works with the recommended use of unsafe
blocks: the code inside it is allowed to do unsafe things but is supposed to leave the result in a safe state.
On the other hand, this kind of static check for various other properties than safe/unsafe would be awesome, for example trusted/untrusted. Imagine if the compiler could tell you that you are injecting a string from the network directly into a shell command.