Rust Safety Rules

    by mochalatte

    1

    Enforce memory safety, FFI soundness, and panic-free library patterns in Rust codebases.

    Secure checkout via Stripe

    0 installsSecurity scanned

    Works with the AI tools you already use

    CClaude CodeCCursorCCodex CLIGGitHub CopilotGGemini CLI+17 more

    See it in action

    You say

    Review this FFI wrapper. I added an unsafe Send impl to move the raw pointer between threads and a bytes method to get a slice. It occasionally crashes.

    Your agent does

    Safety scope

    FFI wrapper for raw pointers.

    Findings

    1. sensor.rs — Unsafe rule 1. Missing SAFETY comment.
    2. sensor.rs — Send rule 2. Unsafe impl Send has no written proof.

    Patch

    // [Patched code with NonNull and SAFETY comments]

    Audit notes

    • Run cargo +nightly miri test.

    What you get

    Enforce SAFETY comments on all unsafe blocks and functions.Audit FFI boundaries for raw pointer and alignment invariants.Eliminate unwrap and panic calls in library crates.Validate hand-written Send and Sync implementations with proofs.Identify borrow checker struggles that signal poor design.

    About this skill

    The problem

    The Rust compiler handles most safety checks, but it cannot verify the invariants inside unsafe blocks, the soundness of FFI wrappers, or hand-written Send and Sync implementations. These blind spots often lead to rare, hard-to-debug segfaults and undefined behavior in production.

    What it does

    • Enforces mandatory SAFETY comments for every unsafe block that explain the invariant being relied upon.
    • Audits ownership patterns to identify when borrow checker struggles indicate a design flaw rather than a syntax error.
    • Flags prohibited panics, unwraps, and expects in library code to prevent process crashes for callers.
    • Verifies that unsafe functions include proper safety sections in doc comments for downstream callers.
    • Reviews hand-written thread-safety claims (Send/Sync) and demands written proof of synchronization.

    Frameworks & tools

    Rust (2021 and 2024 editions), Cargo, thiserror, anyhow, and cargo-deny.

    Why this beats prompting it yourself

    Generic LLMs often suggest fixes that simply silence the compiler without addressing underlying soundness issues. This skill follows a strict "Trigger Matrix" to catch subtle signals like mutex guards crossing await points or missing raw pointer invariants that standard prompting misses.

    Use cases

    • Reviewing FFI wrappers to ensure C pointers are handled safely before dereferencing.
    • Refactoring library code to replace panics with robust error handling using thiserror.
    • Auditing thread-safety implementations in systems-level concurrency primitives.
    • Cleaning up "reflexive cloning" and improper interior mutability patterns.

    Known limitations

    It cannot run cargo commands, Miri, or tests. It only reviews and edits code within the editor based on static analysis of the provided text.

    How to install

    Drop the file into your AI Agent. Works with Claude, Cursor, ChatGPT, and 20+ more.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean today

    Listedtoday

    Frequently Asked Questions

    Popular in Code Review