rust-unsafe

Audit and review unsafe Rust code with lint floors, Miri checks, and FFI layout rules.

2|1|Updated Aug 19, 2026
One-click install
npx skills add https://github.com/po4yka/rust-skills --skill rust-unsafe-po4yka
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-unsafe
Source: https://github.com/po4yka/rust-skills/tree/main/skills/rust-unsafe
Command: npx skills add https://github.com/po4yka/rust-skills --skill rust-unsafe-po4yka

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Unsafe Rust code can compile cleanly while still containing undefined behavior, and standard reviews often miss soundness defects in raw pointers, transmutes, FFI boundaries, and manual Send/Sync impls. This Skill gives a coding agent concrete commands, lint configurations, and triage tables to find, verify, and fix unsafe code systematically. ## Core Features & Use Cases - Unsafe surface inventory: ripgrep and cargo commands to locate every unsafe block, unmangled export, and macro-expanded unsafe code that #![forbid(unsafe_code)] cannot see. - Verification workflow: a tiered check ladder covering clippy lint floors, debug-profile precondition tests, Miri under Stacked Borrows and Tree Borrows, and sanitizer coverage for FFI paths Miri cannot execute. - Triage and pattern references: tables mapping symptoms like E0793, improper_ctypes warnings, and reference fabrication to their causes and fixes, plus detailed references on FFI layout, aliasing models, and audit checklists. - Use Case: When reviewing a pull request that adds an unsafe impl Send or a hand-rolled extern "C" export, the agent runs the inventory, applies the audit checklist, and confirms each unsafe block has a SAFETY comment naming its invariant. ## Quick Start Ask the agent to audit this crate for unsafe code and verify each unsafe block with clippy, debug tests, and Miri.

Frequently Asked Questions about rust-unsafe

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I audit unsafe code in a Rust crate?▼

Run ripgrep over the crate for `unsafe {`, `unsafe fn`, `unsafe impl`, and unmangled export attributes to map the unsafe surface. Then apply `#![forbid(unsafe_code)]` to crates with no hand-written unsafe and enforce a clippy lint floor on crates that contain it.

How to verify unsafe Rust code with Miri?▼

Run `cargo +nightly miri test` under the default Stacked Borrows model first, then Tree Borrows as a second opinion. Add `-Zmiri-symbolic-alignment-check` for byte parsers and `-Zmiri-many-seeds` for threaded code, since one seed explores only one schedule.

Does forbid(unsafe_code) catch unsafe from dependency macros?▼

No, `#![forbid(unsafe_code)]` checks only the crate's own source text, not macro expansions from dependencies. Use `cargo +nightly rustc -- -Zunpretty=expanded` and grep the expansion to find unsafe injected by dependency macros.

Why does ptr::read on a byte slice cause undefined behavior?▼

Bytes from sockets, files, or FFI callers carry arbitrary alignment, and `ptr::read` requires a pointer aligned for the target type. Use `ptr::read_unaligned`, `zerocopy::FromBytes`, or `from_le_bytes` instead, and test under Miri with symbolic alignment checks.

When is mem::zeroed sound to use in Rust?▼

`mem::zeroed()` is sound only when the exact type's documented contract proves all-zero bytes is a valid value. It is never valid for references, NonNull, NonZero, Box, or function pointers; use `MaybeUninit<T>` when no such proof exists.

What are the limits of Miri for FFI code?▼

Miri cannot execute foreign functions, so tests crossing a real FFI boundary must be marked `#[cfg_attr(miri, ignore)]` and covered with ASan, HWASan, or MTE instead. A `#[cfg(miri)]` stub must dereference every stored pointer or aliasing defects pass undetected.