Rustfmt: [Feature Request] Attempt to format brace macros as Block

Created on 13 Mar 2019  路  5Comments  路  Source: rust-lang/rustfmt

For instance,

wrapper! {
use std::  collections::HashMap;
pub fn the (a: sdf )
{
    ( )
}
}

Removing this conditional in rewrite_macro_inner gets most of the way there, but leaves things like Use statements unformatted:

wrapper! {
    use std::  collections::HashMap;
    pub fn the(a: sdf) {
        ()
    }
}
a-macros feature-request

Most helpful comment

In the issue #3434, formatting of such macros is not wanted.

I think when rustfmt sees a macro block, it should check the contents to see if it's valid Rust syntax. If yes, format it as Rust code. If not, leave it alone (under the assumption that it's a different non-Rust language).

The HTML in #3434 is not valid Rust syntax, so it would not be changed. But most uses of macro blocks (the OP, thread_local! {}, etc) are valid Rust syntax, so they would be formatted.

All 5 comments

In the issue #3434, formatting of such macros is not wanted. Maybe there could be a configuration option to toggle formatting of brace macros.

Edit: Actually, it was proposed to extend the skip attribute to prevent formatting a macro https://github.com/rust-lang/rustfmt/issues/3434#issuecomment-470753967

Maybe there could be a configuration option to toggle formatting of brace macros.

A configuration option or an attribute to explicitly enable formatting the inside of a macro with a specific name would be incredibly useful :)

#[rustfmt::noskip]

perhaps?

Building DSL code requires macro block formatting ...

In the issue #3434, formatting of such macros is not wanted.

I think when rustfmt sees a macro block, it should check the contents to see if it's valid Rust syntax. If yes, format it as Rust code. If not, leave it alone (under the assumption that it's a different non-Rust language).

The HTML in #3434 is not valid Rust syntax, so it would not be changed. But most uses of macro blocks (the OP, thread_local! {}, etc) are valid Rust syntax, so they would be formatted.

Was this page helpful?
0 / 5 - 0 ratings