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

Misalignment with or pattern arguments. #4885

Closed
fbernier opened this issue Jun 29, 2021 · 1 comment
Closed

Misalignment with or pattern arguments. #4885

fbernier opened this issue Jun 29, 2021 · 1 comment

Comments

@fbernier
Copy link

fbernier commented Jun 29, 2021

The following code:

fn is_meta_character(c: char) -> bool {
    matches!(
        c,
        '\\' | '.' | '+' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' |
        '$'  | '#' | '&' | '-' | '~' | '*' | '?'
    )
}

gets formatted into

fn is_meta_character(c: char) -> bool {
    matches!(
        c,
        '\\' | '.'
            | '+'
            | '('
            | ')'
            | '|'
            | '['
            | ']'
            | '{'
            | '}'
            | '^'
            | '$'
            | '#'
            | '&'
            | '-'
            | '~'
            | '*'
            | '?'
    )
}

I see two issues with this. First, horizontal bars are misaligned, and second it's a big waste of vertical space. I did not have time to gather more info as of now but will update this issue if I get back to it.

Thanks!

@calebcartwright
Copy link
Member

Thank you for reaching out, but I'm going to close as a duplicate of #4462

Few things to be aware of in this context:

  • rustfmt has fairly limited support for formatting macros (refs format macros #8)
  • When rustfmt encounters macro calls with certain delimiters it will check to see if the inputs can be parsed as valid rust code, and if so then the code is formatted according to the corresponding prescription from the Rust Style Guide
  • matches! calls are currently treated like any other macro call, and since the second arg gets parsed as a binop expression it is formatted accordingly
  • In rare, well known cases, we can add some special case handling for certain macro calls, and ultimately plan to do the same for matches one day too

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

No branches or pull requests

2 participants