How to debug macros

Debug Rust macros by using rustc flags or RUSTFLAGS to expand and inspect the generated code before compilation.

Debug Rust macros by enabling verbose expansion output to inspect the generated code before compilation. Run the following command to expand macros and view the resulting code in the terminal:

rustc -Z macro-backtrace --pretty=expanded your_file.rs

If you are using Cargo, add the RUSTFLAGS environment variable to see macro expansions during the build process:

RUSTFLAGS="-Z macro-backtrace" cargo build