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_matchers] Closure syntax #4116

Open
whatisaphone opened this issue Apr 12, 2020 · 2 comments
Open

[format_macro_matchers] Closure syntax #4116

whatisaphone opened this issue Apr 12, 2020 · 2 comments
Labels
a-macros only-with-option requires a non-default option value to reproduce p-low poor-formatting

Comments

@whatisaphone
Copy link

I occasionally write macros that include faux-closure syntax, for example:

macro_rules! map_and_then_print {
    ($value:expr, |$pat:pat| $map:expr) => {{
        let $pat = $value;
        let s = $map;
        println!("{}", s);
    }};
}

map_and_then_print!(1, |x| x + 3);
// Prints "4"

rustfmt formats the usage as I'd expect:

map_and_then_print!(1, |x| x + 3);

But the declaration gets formatted a bit strangely:

    ($value:expr, | $pat:pat | $map:expr) => {{

rustfmt doesn't understand that it's supposed to resemble a closure, so it puts a few extra spaces in. I would have expected it to look like this:

    ($value:expr, |$pat:pat| $map:expr) => {{

Here is rustfmt.toml:

edition = "2018"
format_macro_matchers = true

Is this kind of thing in scope for the project?

@topecongiro topecongiro added a-macros only-with-option requires a non-default option value to reproduce poor-formatting labels Apr 17, 2020
@topecongiro
Copy link
Contributor

Is this kind of thing in scope for the project?

It is, though it is not the highest priority and very hard to get it done right.

@ytmimi ytmimi added the p-low label Jul 26, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Jul 26, 2022

Confirming this is reproducible with rustfmt 1.5.1-nightly (a451a39d 2022-07-25).

Linking tracking issue for format_macro_matchers #3354

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-macros only-with-option requires a non-default option value to reproduce p-low poor-formatting
Projects
None yet
Development

No branches or pull requests

3 participants