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

Format macro calls (not definitions) #2905

Open
Ekleog opened this issue Aug 8, 2018 · 1 comment
Open

Format macro calls (not definitions) #2905

Ekleog opened this issue Aug 8, 2018 · 1 comment

Comments

@Ekleog
Copy link

Ekleog commented Aug 8, 2018

Hello,

I haven't been able to find this in the issue tracker. If it is there, sorry for missing it!

On IRC, someone wanted to auto-format a big match-like macro, like:

match_any_type!(var, {
    Foo::A => a,
    Foo::B => {
        bar();
        b
    }
    // etc.
})

The use case appears to make sense to me, but I don't think any rust formatting tool is currently able to handle this, as it is completely macro-dependent.

However, @thepowersgang proposed a solution:

Mutabah | [snip] Re getting auto-formatting of macro input - I don't know if there's formatting tools that can do that... a
        | powerful one could possibly look at the macro signature and guess at formatting for fragements                      

IOW, rustfmt could (theoretically) check the macro signature and figure out what parts are of what type, to then try to indent them correctly.

I don't know if this is actually doable within reasonable complexity, but thought this idea was great and deserved to be tracked :)

Anyway, thank you for your work on rustfmt!

@RReverser
Copy link
Contributor

For what it's worth, Rustfmt already tries to format arguments to macros if they look like normal expressions.

So while the example above wouldn't be currently auto-formatted, macro author could change it to accept syntax that looks like actual match expression:

match_any_type!(match var {
    Foo::A => a,
    Foo::B => {
        bar();
        b
    } // etc.
})

and that one would be formatted as expected.

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

No branches or pull requests

3 participants