Any AST Explorer/Pretty Printer?

Are there any tools for displaying a Rust Abstract Syntax Tree nicely?

I'm creating an attribute proc macro that works on functions.

I found one example of such a macro here: syn/examples/trace-var at master · dtolnay/syn · GitHub

It would be much easier to figure AST manipulations if there was a tool to display the AST nicely.

Thanks for any help or advice on working with ASTs.

Will converting the ast back into code suffice? prettyplease - Rust

If you are merely trying to debug the output of a macro, try cargo-epxand.

Thanks for the suggestions! Rust made it easy to create what I needed:
Rust AST Explorer

You paste in any Rust code and it displays the AST. It uses the syn crate (for parsing and formatting) and WASM (for interactivity).

[Update: AST explorer is fancier. I saw it, but missed its Rust option, which is via a pull down.]

Please give it a try.

My hope is that this will make creating procedure macros easier.


Update: I used Rust AST Explorer and the fancier AST Explorer to create a proc macro.
Anyinput -- proc macro to easily create functions that accept any type of string-, path-, iterator-, or array-like inputs - announcements - The Rust Programming Language Forum (

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.