Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Attempt to format brace macros as Block #3445

Closed
nhynes opened this issue Mar 13, 2019 · 6 comments
Closed

[Feature Request] Attempt to format brace macros as Block #3445

nhynes opened this issue Mar 13, 2019 · 6 comments

Comments

@nhynes
Copy link

nhynes commented Mar 13, 2019

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) {
        ()
    }
}
@scampi
Copy link
Contributor

scampi commented Mar 14, 2019

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 #3434 (comment)

@topecongiro topecongiro added this to the 2.0.0 milestone Jun 8, 2019
@arilotter
Copy link

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 :)

@nhynes
Copy link
Author

nhynes commented Dec 18, 2019

#[rustfmt::noskip]

perhaps?

@Hentioe
Copy link

Hentioe commented Feb 15, 2020

Building DSL code requires macro block formatting ...

@whatisaphone
Copy link

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.

@calebcartwright
Copy link
Member

Going to close this in an effort to consolidate duplicative threads.

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 fundamental progress with this is that there's overlap between arg tokens that can be parsed as valid Rust syntax but actually are not, and applying the valid-Rust formatting rules to them can, and has, actually been a problem when using other call delims, with the only viable resolution being to either switch to the brace delim or adding the skip attribute on the call.

It's simply not possible for rustfmt to ever be able to safely make that assumption, which is why a categorical approach is not viable. Something like the more explicit opt-in approaches that have been discussed elsewhere is probably the best middle ground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants