Cursor Skill

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, C

LLM Mart · 0 points · 11 views 0 listing impressions 0 install-command copies
Download moeru-ai-auv-.agents_skills_unsafe-checker-372a07b.zip · 81 KB

Install

skills CLI npx skills add https://github.com/moeru-ai/auv/tree/main/.agents/skills/unsafe-checker
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install moeru-ai-auv@llmmart
Git git clone https://github.com/moeru-ai/auv.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole moeru-ai/auv collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

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 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.

Files (auv)
  • checklists
    • before-unsafe.md 3.3 KB
      Loading…
    • common-pitfalls.md 4.5 KB
      Loading…
    • review-unsafe.md 3.8 KB
      Loading…
  • examples
    • ffi-patterns.md 8.8 KB
      Loading…
    • safe-abstraction.md 6.9 KB
      Loading…
  • rules
    • ffi-01-no-string-direct.md 2.9 KB
      Loading…
    • ffi-02-read-ffi-docs.md 3.2 KB
      Loading…
    • ffi-03-drop-for-c-ptr.md 3.6 KB
      Loading…
    • ffi-04-panic-boundary.md 3.6 KB
      Loading…
    • ffi-05-portable-types.md 2.6 KB
      Loading…
    • ffi-06-string-abi.md 3.1 KB
      Loading…
    • ffi-07-no-drop-external.md 3.2 KB
      Loading…
    • ffi-08-error-handling.md 3.5 KB
      Loading…
    • ffi-09-ref-not-ptr.md 3.1 KB
      Loading…
    • ffi-10-thread-safety.md 3.2 KB
      Loading…
    • ffi-11-packed-ub.md 3.1 KB
      Loading…
    • ffi-12-invariant-doc.md 3.9 KB
      Loading…
    • ffi-13-data-layout.md 3.1 KB
      Loading…
    • ffi-14-stable-layout.md 3 KB
      Loading…
    • ffi-15-validate-external.md 3.6 KB
      Loading…
    • ffi-16-closure-to-c.md 3.5 KB
      Loading…
    • ffi-17-opaque-types.md 3.8 KB
      Loading…
    • ffi-18-no-trait-objects.md 3.8 KB
      Loading…
    • general-01-no-abuse.md 1.8 KB
      Loading…
    • general-02-not-for-perf.md 2.3 KB
      Loading…
    • general-03-no-alias.md 2 KB
      Loading…
    • io-01-raw-handle.md 3.7 KB
      Loading…
    • mem-01-repr-layout.md 2.9 KB
      Loading…
    • mem-02-no-other-process.md 3.1 KB
      Loading…
    • mem-03-no-auto-drop-foreign.md 3.2 KB
      Loading…
    • mem-04-reentrant.md 3.1 KB
      Loading…
    • mem-05-bitfield-crates.md 3.2 KB
      Loading…
    • mem-06-maybeuninit.md 3.8 KB
      Loading…
    • ptr-01-no-thread-share.md 2.9 KB
      Loading…
    • ptr-02-prefer-nonnull.md 2.7 KB
      Loading…
    • ptr-03-phantomdata.md 3.1 KB
      Loading…
    • ptr-04-alignment.md 3.1 KB
      Loading…
    • ptr-05-no-const-to-mut.md 2.8 KB
      Loading…
    • ptr-06-prefer-cast.md 3 KB
      Loading…
    • safety-01-panic-safety.md 2.9 KB
      Loading…
    • safety-02-verify-invariants.md 2.5 KB
      Loading…
    • safety-03-no-uninit-api.md 2.9 KB
      Loading…
    • safety-04-double-free.md 2.8 KB
      Loading…
    • safety-05-send-sync.md 2.9 KB
      Loading…
    • safety-06-no-raw-ptr-api.md 3.1 KB
      Loading…
    • safety-07-unsafe-pair.md 2.9 KB
      Loading…
    • safety-08-no-mut-from-immut.md 2.8 KB
      Loading…
    • safety-09-safety-comment.md 3.2 KB
      Loading…
    • safety-10-safety-doc.md 3.3 KB
      Loading…
    • safety-11-assert-not-debug.md 3.1 KB
      Loading…
    • union-01-avoid-except-ffi.md 2.6 KB
      Loading…
    • union-02-no-cross-lifetime.md 2.9 KB
      Loading…
    • _sections.md 1.9 KB
      Loading…
    • _template.md 765 B
      Loading…
  • AGENTS.md 5.1 KB
    Loading…
  • SKILL.md 2.4 KB
    ---
    name: unsafe-checker
    description: "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 绑定, 未定义行为"
    globs: ["**/*.rs"]
    allowed-tools: ["Read", "Grep", "Glob"]
    ---
    
    Display the following ASCII art exactly as shown. Do not modify spaces or line breaks:
    ```text
    ⚠️ **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
    
    ```rust
    // 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 (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.