rust-sanitizers-miri

Run Miri and sanitizers on Rust code to detect undefined behavior and memory errors.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Rust code with unsafe blocks and FFI can contain undefined behavior that the compiler cannot catch, and developers struggle to choose between Miri, ASan, TSan, MSan, HWASan, and MTE, configure their flags correctly, and interpret their reports. ## Core Features & Use Cases - Tool Selection and Triage: Maps each bug class (aliasing violations, use-after-free, data races, uninitialized reads) to the correct tool, with failure-triage tables matching Miri and ASan error messages to probable causes and fixes. - Concrete Run Commands: Provides copy-paste commands for host sanitizers with -Zbuild-std, Miri jobs with MIRIFLAGS like -Zmiri-strict-provenance and -Zmiri-tree-borrows, plus Android HWASan/MTE and iOS Xcode sanitizer setups. - FFI Stubbing Guidance: Shows how to write #[cfg(miri)] stubs that preserve signatures and pointer semantics so Miri still detects Box-plus-FFI aliasing defects. - Use Case: A pull request adds raw-pointer parsing code. Use this Skill to gate it with cargo +nightly miri test under Stacked Borrows and symbolic alignment checks, add a Tree Borrows run as extra evidence, and cover the FFI paths Miri skips with an ASan job in CI. ## Quick Start Ask the agent to set up a Miri and AddressSanitizer CI pipeline for a Rust crate that contains unsafe code and a C dependency.

Frequently Asked Questions about rust-sanitizers-miri

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

FAQPage Schema
How do I run Miri on Rust tests?▼

Install the Miri component with `rustup +nightly component add miri`, then run `cargo +nightly miri test --locked`. Filter to one test with a test name argument, and keep the Miri test set small since interpretation is much slower than native execution.

Miri vs ASan: which should I use for Rust unsafe code?▼

Miri detects aliasing, provenance, and invalid-value violations per Rust rules but cannot execute foreign code. ASan finds heap overflows and use-after-free at runtime including in C dependencies. For crates with both unsafe and FFI, run both tools.

How do I run AddressSanitizer on a Rust project?▼

Use nightly with `RUSTFLAGS="-Zsanitizer=address"` and `cargo +nightly test -Zbuild-std --target <host>`. The `-Zbuild-std` flag is required because the prebuilt standard library is not instrumented, and `--target` keeps flags off proc macros.

Why does Miri fail with 'can't call foreign function'?▼

Miri cannot interpret C, C++, JNI, or inline assembly. Gate your own `extern "C"` declarations with `#[cfg(not(miri))]` and add a `#[cfg(miri)]` stub with the same signature, or exclude third-party -sys crates from the Miri run and cover them with ASan.

Should I use Stacked Borrows or Tree Borrows with Miri?▼

Run Stacked Borrows first as the gate since it is the default model. Add Tree Borrows via `MIRIFLAGS="-Zmiri-tree-borrows"` only as extra evidence on raw-pointer crates, because Tree Borrows accepts some patterns Stacked Borrows rejects and is more experimental.

Can Xcode sanitizers check a prebuilt Rust static library?▼

No. Xcode instruments only code it compiles, so a prebuilt Rust staticlib gets no ASan or TSan instrumentation from the scheme setting. Run ASan and TSan against a supported host Rust target for that coverage instead.