unsafe-checker

Verified·Scanned 2/17/2026

This skill is a comprehensive rulebook and checklists for reviewing unsafe Rust and FFI code. It contains inline developer commands such as cargo bench --bench my_bench, cargo flamegraph --bench my_bench, cargo miri test and setting RUSTFLAGS="-Zsanitizer=address".

by zhanghandong·v3ea7482·182.2 KB·238 installs
Scanned from main at 3ea7482 · Transparency log ↗
$ vett add zhanghandong/rust-skills/unsafe-checker

Display 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 CaseExample
FFICalling C functions
Low-level abstractionsImplementing Vec, Arc
PerformanceMeasured 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

OperationSafety Requirements
*ptr derefValid, aligned, initialized
&*ptr+ No aliasing violations
transmuteSame size, valid bit pattern
extern "C"Correct signature, ABI
static mutSynchronization guaranteed
impl Send/SyncActually thread-safe

Common Errors

ErrorFix
Null pointer derefCheck for null before deref
Use after freeEnsure lifetime validity
Data raceAdd proper synchronization
Alignment violationUse #[repr(C)], check alignment
Invalid bit patternUse MaybeUninit
Missing SAFETY commentAdd // SAFETY:

Deprecated → Better

DeprecatedUse Instead
mem::uninitialized()MaybeUninit<T>
mem::zeroed() for refsMaybeUninit<T>
Raw pointer arithmeticNonNull<T>, ptr::add
CString::new().unwrap().as_ptr()Store CString first
static mutAtomicT or Mutex
Manual externbindgen

FFI Crates

DirectionCrate
C → Rustbindgen
Rust → Ccbindgen
PythonPyO3
Node.jsnapi-rs

Claude knows unsafe Rust. Focus on SAFETY comments and soundness.