How to Use Address Sanitizer (ASan) with Rust

Enable Address Sanitizer in Rust by setting RUSTFLAGS to -Zsanitizer=address and building with a nightly toolchain.

Enable Address Sanitizer (ASan) by setting the RUSTFLAGS environment variable to include -Zsanitizer=address before running cargo build.

export RUSTFLAGS="-Zsanitizer=address"
cargo build

This requires a nightly Rust toolchain. Run cargo +nightly build if your default toolchain is stable.