Your best bet if you want to play with these directly is to write a rustc plugin. If you go this route you may want to tie your project to a specific nightly with a
I've never written one myself but there are a number of things that I can suggest looking at:
rocket_codegen pre-4.0 is a decent example of how to define a special attribute you can place on items that is capable of inspecting their HIR.
Examples of how to inspect
mir can be found in
If you're curious about really low level stuff, to my (limited) knowledge, the textual form of LLVM IR is normative. Perhaps there's a decent parser for it somewhere. (maybe)
I know there's another intermediate representation called the HAIR that sits between the HIR and MIR:
The rustc guide:
The HAIR's most important feature is that the various adjustments (which happen without explicit syntax) like coercions, autoderef, autoref and overloaded method calls have become explicit casts, deref operations, reference expressions or concrete function calls.
I wouldn't know of any examples of tools that actually look at this (I think it's just an implementation detail of the lowering and so it's simply not useful?), but if you're just curious how the compiler works then if there's a will there's probably a way.
Note: I've heard claims on here that plugins are being removed, but am not sure what these claims are based on. Without a doubt, the goal is that eventually all libraries intended for wide consumption should be powered by stable
proc_macros rather than hideously unstable rustc plugins; but when the goal is precisely to peek at rustc's current infrastructure, what could be better? (and besides,
clippy needs the infrastructure...)
I have read about the syntex_syntax crate, but it is over 2 years old, so I guess it's not my best option.
This crate was superceded by
syn is great for parsing the rust AST and is definitely a tool you'll want when writing
proc_macros. However, it won't give you access to the deeper IRs you are interested in looking at.