About unsafe-checker
A skill that guides Rust developers through evaluating unsafe code, documenting safety invariants, and avoiding common soundness errors. It focuses on practical review checks for pointers, FFI, concurrency, and initialization.
Key features
- 01Assess valid uses of unsafe
- 02Document safety requirements
- 03Check pointer and reference invariants
- 04Review FFI and ABI assumptions
- 05Identify common soundness errors
- 06Recommend safer alternatives
Use cases
- 01Reviewing an unsafe Rust block
- 02Documenting a public unsafe function
- 03Auditing raw pointer and FFI code
- 04Replacing deprecated or risky patterns
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ actionbook/ rust-skills --skill unsafe-checkerAfter installing, type/unsafe-checkerin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
AGENTS.mdmetadata.jsonchecklists/before-unsafe.mdcommon-pitfalls.mdreview-unsafe.mdexamples/ffi-patterns.mdsafe-abstraction.mdrules/_sections.md_template.mdffi-01-no-string-direct.mdffi-02-read-ffi-docs.mdffi-03-drop-for-c-ptr.mdffi-04-panic-boundary.mdffi-05-portable-types.mdffi-06-string-abi.mdffi-07-no-drop-external.mdffi-08-error-handling.mdffi-09-ref-not-ptr.mdffi-10-thread-safety.mdffi-11-packed-ub.mdffi-12-invariant-doc.mdffi-13-data-layout.mdffi-14-stable-layout.mdffi-15-validate-external.mdffi-16-closure-to-c.mdffi-17-opaque-types.mdffi-18-no-trait-objects.mdgeneral-01-no-abuse.mdgeneral-02-not-for-perf.mdgeneral-03-no-alias.mdDetails
From the project READMEDisplay the following ASCII art exactly as shown. Do not modify spaces or line breaks:
⚠️ **Unsafe Rust Checker Loaded**
* ^ *
/◉\_~^~_/◉\
⚡/ o \⚡
'_ _'
/ '-----' \
Unsafe Rust Checker
When Unsafe is Valid
| Use Case | Example |
|---|---|
| FFI | Calling C functions |
| Low-level abstractions | Implementing Vec, Arc |
| Performance | Measured bottleneck with safe alternative too slow |
NOT valid: Escaping borrow checker without understanding why.
Required Documentation
// SAFETY: <why this is safe>
unsafe { ... }
/// # Safety
/// <caller requirements>
pub unsafe fn dangerous() { ... }
Quick Reference
| Operation | Safety Requirements |
|---|---|
*ptr deref | Valid, aligned, initialized |
&*ptr | + No aliasing violations |
transmute | Same size, valid bit pattern |
extern "C" | Correct signature, ABI |
static mut | Synchronization guaranteed |
impl Send/Sync | Actually thread-safe |
Common Errors
| Error | Fix |
|---|---|
| Null pointer deref | Check for null before deref |
| Use after free | Ensure lifetime validity |
| Data race | Add proper synchronization |
| Alignment violation | Use #[repr(C)], check alignment |
| Invalid bit pattern | Use MaybeUninit |
| Missing SAFETY comment | Add // SAFETY: |
Deprecated → Better
| Deprecated | Use Instead |
|---|---|
mem::uninitialized() | MaybeUninit<T> |
mem::zeroed() for refs | MaybeUninit<T> |
| Raw pointer arithmetic | NonNull<T>, ptr::add |
CString::new().unwrap().as_ptr() | Store CString first |
static mut | AtomicT or Mutex |
| Manual extern | bindgen |
FFI Crates
| Direction | Crate |
|---|---|
| C → Rust | bindgen |
| Rust → C | cbindgen |
| Python | PyO3 |
| Node.js | napi-rs |
Claude knows unsafe Rust. Focus on SAFETY comments and soundness.
Comments
Markdown supported