rust-lang / rust-lang/rustfmt

Add special case handling for matches! to format args as patterns

Open
#4,462 5 comments 1 reaction 1 assignee View on GitHub

@topecongiro is already working on this.

Since Oct 10, 2020.

A-macros C-feature-request I-poor-formatting P-low
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Input

        matches!(c,
            'x' | 'c' | 'b' | 'B' | '?' | 'h' | 'H' | 'i' | 'I' | 'l' | 'L' | 'q' | 'Q' | 'n'
            | 'N' | 'f' | 'd' | 's' | 'p' | 'P')

Output

        matches!(
            c,
            'x' | 'c'    // <- this part make inconsistency of the formatting
                | 'b'
                | 'B'
                | '?'
                | 'h'
                | 'H'
                | 'i'
                | 'I'
                | 'l'
                | 'L'
                | 'q'
                | 'Q'
                | 'n'
                | 'N'
                | 'f'
                | 'd'
                | 's'
                | 'p'
                | 'P'
        )

Expected output

I expect the input form

        matches!(c,
            'x' | 'c' | 'b' | 'B' | '?' | 'h' | 'H' | 'i' | 'I' | 'l' | 'L' | 'q' | 'Q' | 'n'
            | 'N' | 'f' | 'd' | 's' | 'p' | 'P')

Because it is the closest when we use match

        match c {
            'x' | 'c' | 'b' | 'B' | '?' | 'h' | 'H' | 'i' | 'I' | 'l' | 'L' | 'q' | 'Q' | 'n'
            | 'N' | 'f' | 'd' | 's' | 'p' | 'P' => true,
            _ => false,
        }

Or this kind of form is also acceptable in term of consistency

        matches!(
            c,
            'x' 
            | 'c'
            | 'b'
            | 'B'
            | '?'
            | 'h'
            | 'H'
            | 'i'
            | 'I'
            | 'l'
            | 'L'
            | 'q'
            | 'Q'
            | 'n'
            | 'N'
            | 'f'
            | 'd'
            | 's'
            | 'p'
            | 'P'
        )

Meta

  • rustfmt version: 1.4.20-stable (48f6c32e 2020-08-09)
  • From where did you install rustfmt?: rustup

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.