Rust Sanitizers and Miri
Purpose
Guide agents through runtime safety validation for Rust: ASan/TSan/MSan/UBSan via RUSTFLAGS, Miri for compile-time UB detection in unsafe code, and interpreting sanitizer reports.
Triggers
- "How do I run AddressSanitizer on Rust code?"
- "How do I use Miri to check my unsafe Rust?"
- "How do I run ThreadSanitizer on a Rust program?"
- "My unsafe Rust might have UB — how do I detect it?"
- "How do I interpret a Rust ASan report?"
- "Can I run Rust sanitizers on stable?"
Workflow
1. Sanitizers in Rust (nightly required)
Rust sanitizers require nightly and a compatible platform:
-Zbuild-std rebuilds the standard library with the sanitizer, which is necessary for accurate results.
2. Stable sanitizer workaround
For stable Rust, use the cross tool with a Docker image that has sanitizers pre-configured, or run cargo test inside a Docker container with a nightly image.
Alternatively, for simpler UB checking without nightly:
3. Interpreting ASan output in Rust
Rust-specific patterns:
4. Miri — interpreter for undefined behaviour
Miri interprets Rust MIR and detects UB that sanitizers might miss:
5. What Miri detects
6. ThreadSanitizer for Rust
TSan output:
7. Miri configuration via MIRIFLAGS
8. CI integration
Related skills
- Use
skills/rust/rust-debuggingfor GDB/LLDB debugging of Rust panics - Use
skills/runtimes/sanitizersfor C/C++ sanitizer usage and comparison - Use
skills/rust/rust-unsafefor unsafe Rust patterns and review checklist - Use
skills/runtimes/fuzzingto generate inputs that trigger sanitizer errors


