actionbook/rust-skills57 files

Unsafe Checker

CRITICAL: Use for unsafe Rust code review and FFI. Triggers on: unsafe, raw pointer, FFI, extern, transmute, *mut, *const, union, #[repr(C)], libc, std::ffi, MaybeUninit, NonNull, SAFETY comment, soundness, undefined behavior, UB, safe wrapper, memory layout, bindgen, cbindgen, CString, CStr, 安全抽象, 裸指针, 外部函数接口, 内存布局, 不安全代码, FFI 绑定, 未定义行为

Specification
Skill ID
actionbook/rust-skills/unsafe-checker
Publisher
actionbook
Repository
rust-skills
Installs
0
Files
57
Synced
Sep 23, 2026
How to use it

Open any RiverX project, open the Skills panel in the chat, and search for this identifier. The files are fetched from the source repository at install time.

actionbook/rust-skills/unsafe-checkerInstalls these files
  • AGENTS.md
  • SKILL.md
  • checklists/before-unsafe.md
  • checklists/common-pitfalls.md
  • checklists/review-unsafe.md
  • examples/ffi-patterns.md
  • examples/safe-abstraction.md
  • metadata.json
  • rules/_sections.md
  • rules/_template.md
  • rules/ffi-01-no-string-direct.md
  • rules/ffi-02-read-ffi-docs.md
  • rules/ffi-03-drop-for-c-ptr.md
  • rules/ffi-04-panic-boundary.md
  • rules/ffi-05-portable-types.md
  • rules/ffi-06-string-abi.md
  • rules/ffi-07-no-drop-external.md
  • rules/ffi-08-error-handling.md
  • rules/ffi-09-ref-not-ptr.md
  • rules/ffi-10-thread-safety.md
  • rules/ffi-11-packed-ub.md
  • rules/ffi-12-invariant-doc.md
  • rules/ffi-13-data-layout.md
  • rules/ffi-14-stable-layout.md
  • rules/ffi-15-validate-external.md
  • rules/ffi-16-closure-to-c.md
  • rules/ffi-17-opaque-types.md
  • rules/ffi-18-no-trait-objects.md
  • rules/general-01-no-abuse.md
  • rules/general-02-not-for-perf.md
  • rules/general-03-no-alias.md
  • rules/io-01-raw-handle.md
  • rules/mem-01-repr-layout.md
  • rules/mem-02-no-other-process.md
  • rules/mem-03-no-auto-drop-foreign.md
  • rules/mem-04-reentrant.md
  • rules/mem-05-bitfield-crates.md
  • rules/mem-06-maybeuninit.md
  • rules/ptr-01-no-thread-share.md
  • rules/ptr-02-prefer-nonnull.md
  • rules/ptr-03-phantomdata.md
  • rules/ptr-04-alignment.md
  • rules/ptr-05-no-const-to-mut.md
  • rules/ptr-06-prefer-cast.md
  • rules/safety-01-panic-safety.md
  • rules/safety-02-verify-invariants.md
  • rules/safety-03-no-uninit-api.md
  • rules/safety-04-double-free.md
  • rules/safety-05-send-sync.md
  • rules/safety-06-no-raw-ptr-api.md
  • rules/safety-07-unsafe-pair.md
  • rules/safety-08-no-mut-from-immut.md
  • rules/safety-09-safety-comment.md
  • rules/safety-10-safety-doc.md
  • rules/safety-11-assert-not-debug.md
  • rules/union-01-avoid-except-ffi.md
  • rules/union-02-no-cross-lifetime.md

What this skill tells the agent

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.

Use this skill in a project

Open any RiverX project, search the Skills panel for actionbook/rust-skills/unsafe-checker, and install it in one click.

Use this skill