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

rustfmt thinks that a pattern matching is a closure #5709

Open
real-felix opened this issue Mar 9, 2023 · 1 comment · May be fixed by #5554
Open

rustfmt thinks that a pattern matching is a closure #5709

real-felix opened this issue Mar 9, 2023 · 1 comment · May be fixed by #5554
Labels
a-matches match arms, patterns, blocks, etc poor-formatting

Comments

@real-felix
Copy link

When formatting this code:

fn is_something(foo: Foo, bar: Bar) -> bool {
    matches!((legacy_required_finality, signature_weight),
        | (LegacyRequiredFinality::Any, Insufficient | Weak | Strict)
        | (LegacyRequiredFinality::Weak, Weak | Strict)
        | (LegacyRequiredFinality::Strict, Strict)
    )
}

It is written like that:

fn is_something(foo: Foo, bar: Bar) -> bool {
    matches!((legacy_required_finality, signature_weight), |(
        LegacyRequiredFinality::Any,
        Insufficient | Weak | Strict,
    )| (
        LegacyRequiredFinality::Weak,
        Weak | Strict
    ) | (
        LegacyRequiredFinality::Strict,
        Strict
    ))
}

I think that rustfmt sees it as a closure.

I tried to reproduce with a simpler example, but it doesn't work. I think it comes from diverse things, like the fact there is a tuple.

@ytmimi
Copy link
Contributor

ytmimi commented Mar 9, 2023

Thanks for reaching out. Confirming I can reproduce this using rustfmt 1.5.2-nightly (34f9ca28 2023-02-16). I also believe your assumption about this being parsed as a closure is correct.

The issue here is that rustfmt doesn't currently have any special case handling for the matches! macro, however I just looked into it and I believe #5554 would resolve this issue. I've updated the PR to include a test case for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-matches match arms, patterns, blocks, etc poor-formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants