Rust Tooling and Code Quality

Sanitizers and Platform Support

While Miri interprets pure Rust MIR in a virtual machine, compiler sanitizers (such as AddressSanitizer, ThreadSanitizer, MemorySanitizer, and LeakSanitizer) instrument native machine code generated by LLVM so you can detect memory corruption and data races at near-native speed—including across C/C++ FFI boundaries that Miri cannot interpret.

When to Use Miri vs LLVM Sanitizers:

  Pure Rust `unsafe` Code (Pointers, MaybeUninit, Atomics):
    ---> Use `cargo +nightly miri test` (Catches Rust-specific Stacked/Tree Borrows UB!)

  Mixed Rust + C/C++ FFI (`extern "C"`, OS Syscalls, Native Libraries):
    ---> Use LLVM Sanitizers (`-Zsanitizer=address` / `thread` / `memory` / `leak`)

LLVM Sanitizers Supported by rustc

Sanitizer -Zsanitizer=<name> What It Detects at Runtime Typical Slowdown
AddressSanitizer (ASan) address Out-of-bounds heap/stack/global accesses, use-after-free, double-free across Rust and C/C++ FFI. ~2x
ThreadSanitizer (TSan) thread Data races where two threads access the same memory location concurrently without synchronization. ~5x–10x
MemorySanitizer (MSan) memory Reads of uninitialized memory across Rust and C/C++ (requires rebuilding std via -Zbuild-std). ~3x
LeakSanitizer (LSan) leak Heap memory allocations that remain unreachable at process exit. ~1.1x
Hardware-Assisted ASan (HWASan) hwaddress Same as ASan using AArch64 top-byte-ignore (TBI) pointer tagging with lower RAM overhead. ~2x
# Run tests with AddressSanitizer on Linux or macOS (nightly compiler flag):
RUSTFLAGS="-Zsanitizer=address" cargo +nightly test --target x86_64-unknown-linux-gnu

# Run multi-threaded tests with ThreadSanitizer to detect data races:
RUSTFLAGS="-Zsanitizer=thread" cargo +nightly test --target aarch64-apple-darwin

Rust Target Tiers and Platform Support

Rust classifies every supported operating system and CPU architecture (target triple, structured as <arch>-<vendor>-<os>-<env>) into three official Support Tiers:

Support Tier Automated CI Guarantees Example Target Triples
Tier 1 ("Guaranteed to Work") Official binary releases; every commit to rust-lang/rust must pass the full compiler and standard library test suite on that platform before merging. x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, aarch64-apple-darwin, x86_64-pc-windows-msvc
Tier 2 ("Guaranteed to Build") Official binary releases (rustup target add <triple>); CI verifies that std and core compile cleanly on every commit, though full host test suites may not run on every PR. wasm32-unknown-unknown, wasm32-wasip1, x86_64-unknown-linux-musl, aarch64-linux-android, thumbv7em-none-eabihf
Tier 3 ("Best-Effort Community Support") Source support present in rustc, but not built automatically by official CI; requires building core/std locally via cargo +nightly build -Zbuild-std. Retro/niche OSes and specialized microcontroller architectures
use std::env;

fn describe_host_platform() -> String {
    format!(
        "arch={}, os={}, family={}, pointer_width={}-bit",
        env::consts::ARCH,
        env::consts::OS,
        env::consts::FAMILY,
        usize::BITS
    )
}

fn main() {
    println!("Host platform: {}", describe_host_platform());
}
Host platform: arch=aarch64, os=macos, family=unix, pointer_width=64-bit