Does rustfmt format macro calls? #5437
-
Can/does rustfmt format macro calls? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The short answer is: sometimes, but only in certain cases rustfmt is a Rust code formatter which operates as a pretty-printer of the parsed AST (Abstract Syntax Tree) representation of a Rust program. rustfmt has rules defined for each type of AST node it could encounter, such as a match expression, or a function definition, and as rustfmt walks the AST of a program it emits the formatted result for each node it encounters according to the corresponding rules. However, macros can be, and often are, used to extend the language with syntax that isn't directly valid Rust syntax, for example the However, there has been a sizeable desire from the community over the years for rustfmt to try to support formatting macro calls, and there are plenty of macros that are called with args that are valid Rust syntax which rustfmt could format. As such rustfmt currently:
We hope to continue improving macro support over time, and there are various open discussions on the topic which can be found by searching in the issue tracker. |
Beta Was this translation helpful? Give feedback.
The short answer is: sometimes, but only in certain cases
rustfmt is a Rust code formatter which operates as a pretty-printer of the parsed AST (Abstract Syntax Tree) representation of a Rust program. rustfmt has rules defined for each type of AST node it could encounter, such as a match expression, or a function definition, and as rustfmt walks the AST of a program it emits the formatted result for each node it encounters according to the corresponding rules.
However, macros can be, and often are, used to extend the language with syntax that isn't directly valid Rust syntax, for example the
html!
macro provided by the yew crate. rustfmt sees these macro calls in their raw form with arg t…