Home Explore Blog CI



rustc

1st chunk of `src/hir-debugging.md`
250eb607f587705f9287cddafec7ad81b3b90dcd0f3c642400000001000002c6
# HIR Debugging

Use the `-Z unpretty=hir` flag to produce a human-readable representation of the HIR.
For cargo projects this can be done with `cargo rustc -- -Z unpretty=hir`.
This output is useful when you need to see at a glance how your code was desugared and transformed
during AST lowering.

For a full `Debug` dump of the data in the HIR, use the `-Z unpretty=hir-tree` flag.
This may be useful when you need to see the full structure of the HIR from the perspective of the
compiler.

If you are trying to correlate `NodeId`s or `DefId`s with source code, the
`-Z unpretty=expanded,identified` flag may be useful.

TODO: anything else? [#1159](https://github.com/rust-lang/rustc-dev-guide/issues/1159)

Title: HIR Debugging Tools and Techniques
Summary
This section describes how to use the `-Z unpretty` flag with different options (hir, hir-tree, expanded,identified) to debug the High-Level Intermediate Representation (HIR) of Rust code. These flags allow you to view the desugared code, inspect the full HIR structure, and correlate NodeId/DefId with source code.