rust-unsafe-fundamentalslisted
Install: claude install-skill takurot/rust-skills-comprehensive
# Rust Unsafe Fundamentals
`rust-patterns` has a short "when unsafe is/isn't acceptable" section. This skill is the
practical how-to for the five things `unsafe` actually unlocks, each with the specific
footguns the course calls out. For deriving/documenting safety preconditions rigorously and
reasoning about soundness end-to-end, see `rust-unsafe-soundness`; for `Pin`, see
`rust-pinning`; for calling C/C++ specifically, see `rust-ffi`.
## What `unsafe` actually is
Rust is two languages: **Safe Rust** (memory safety and no UB, always, mechanically enforced)
and **Unsafe Rust** (can trigger undefined behavior if you violate a precondition — the
compiler stops checking, you're now responsible). `unsafe` does **not** mean "this code is
wrong" — it means "some of the compiler's automatic safety checks are turned off here, and a
human has to have verified correctness instead." The five things `unsafe` unlocks, and only
these five:
1. Dereference raw pointers
2. Read or write mutable `static` variables
3. Access `union` fields
4. Call `unsafe fn`s, including `extern` functions
5. Implement `unsafe trait`s
Everything else in an `unsafe { }` block is still checked normally by the compiler — `unsafe`
doesn't turn off borrow checking or type checking generally, only these five specific things.
**House rule**: keep unsafe code small and isolated, wrap it in a safe abstraction at the
boundary, and document every precondition. Most unsafe you write should be invisible to
callers of