An unsafe block marks code where Rust cannot verify every safety guarantee. It does not automatically make the code wrong; it signals that the programmer must uphold the missing safety invariants. section 16.4.1
Rust requires an unsafe block when calling an unsafe function. The compiler first rejects the call, then accepts it after the call is placed inside an explicitly marked block. section 16.4.1
Use unsafe blocks sparingly and understand what responsibility they introduce:
- Use them for low-level system resources, foreign-language functions such as libc bindings, unsafe functions, and mutable statics. section 16.4.1 section 16.6
- Treat the block as a deliberate trust boundary: the compiler permits operations it could not otherwise verify, while the programmer must prevent undefined behavior. section 16.4.1 section 16.4.2
Mutable static and data races
A mutable static can be changed or printed only inside an unsafe block. That permission does not make concurrent access safe: multiple threads incrementing the same value can produce inconsistent results because aliasing violations or data races cause undefined behavior. section 16.4.2


