| name | unsafe-review |
| description | Review Rust unsafe blocks for SAFETY comments (what/why/invariants). Use when writing or reviewing unsafe Rust. |
| metadata | {"author":"tz-forge","version":"1.0","source":"adapted from SpectreOS skills/unsafe-review (genericized)"} |
| allowed-tools | Bash(rg:*) Bash(git:*) |
Unsafe code review
Ensure every unsafe block documents why it is sound.
When to use
- Writing new
unsafe blocks
- Reviewing PRs that touch
unsafe
- Auditing FFI, raw pointers, or transmute usage
Requirements
Every unsafe block MUST have a SAFETY: comment covering:
- What — operation / memory / invariant being trusted
- Why — validation, type invariants, API contracts, or hardware guarantees
- References — standard/docs/crate API when non-obvious
Good
unsafe {
let _ = Box::from_raw(ptr);
}
Bad
unsafe {
*p = 1;
}
Review steps
- Find blocks:
rg -n "unsafe\s*(\{|fn|impl|trait|extern)" --type rust
-
For each hit, check:
-
Common patterns:
- Raw pointers — non-null, aligned, initialized, provenance
- FFI — ABI, lifetimes, nullability, thread-safety
- Transmute — size/align equal; prefer
bytemuck / safe casts
- Static mut — exclusive access story
Output
Unsafe review
=============
Blocks found: N
Missing/weak SAFETY: (file:line …)
OK: (file:line …)
Verdict: pass | needs-work