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 fails to format matches! call with enum wildcard destructuring and joined patterns #4512

Closed
matthiaskrgr opened this issue Nov 4, 2020 · 3 comments
Assignees

Comments

@matthiaskrgr
Copy link
Member

Input

enum X {
    A(String),
    B(u32),
}

fn fun(a: X, b: X) -> bool {
    matches!((a,b), (X::A(_),

X::B(_))|
(X::B(_),


 X::A(_)))
}

Output

enum X {
    A(String),
    B(u32),
}

fn fun(a: X, b: X) -> bool {
    matches!((a,b), (X::A(_),

X::B(_))|
(X::B(_),


 X::A(_)))
}

Expected output
something more like:

enum X {
    A(String),
    B(u32),
}

fn fun(a: X, b: X) -> bool {
    matches!((a ,b),
           (X::A(_), X::B(_))
           | (X::B(_), X::A(_)))
}

Meta
rustfmt 1.4.22-nightly (97d0301 2020-10-04)

  • From where did you install rustfmt?: rustup>
@calebcartwright calebcartwright changed the title rustfmt fails to format match matching on tuples of enums rustfmt fails to format matches! call with enum wildcard destructuring and joined patterns Nov 5, 2020
@calebcartwright
Copy link
Member

This doesn't really have anything to do with tuples, and despite the semantics, nor with matches either. The issue is really with the failure to parse that second arg which occurs when there's both a semantic enum wildcard destruct and a | operator from a pattern join.

Simple repro with exaggerated spacing for effect to show rustfmt bailing and reverting to the original formatting:

fn f() {
    matches!(c,
    
    A(_)| 
    
    B(_)
);
            }

@calebcartwright
Copy link
Member

This has been fixed, presumably via the various upstream work in rustc around the token streams/macro handling. Improvements are already available on master, and included in the upcoming v1.4.28 release.

Closing accordingly

@matthiaskrgr
Copy link
Member Author

that's great to hear! :)

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