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

Needlessly large expansion when using '@' sign to bind names to certain patterns #4133

Closed
kaikalii opened this issue Apr 21, 2020 · 1 comment

Comments

@kaikalii
Copy link

I have a struct like this:

struct Foo {
    val: u32,
    kinda_long_field_name: bool,
}

I want to do a match on a value of type Result<Foo, _>, which I think should probably be formatted like this:

#[rustfmt::skip]
match foo {
    Ok(f @ Foo {
        kinda_long_field_name: false,
        ..
    }) => {},
    Ok(Foo {
        val,
        kinda_long_field_name,
    }) => {},
    Err(()) => {},
}

However, it gets weirdly formatted to this:

match foo {
    Ok(
        f
        @ Foo {
            kinda_long_field_name: false,
            ..
        },
    ) => {}
    Ok(Foo {
        val,
        kinda_long_field_name,
    }) => {}
    Err(()) => {}
}

...which I think is kind of odd behavior.

I know that '@' and this kind of name-to-pattern binding is pretty niche and uncommon, but I think it should probably still format in a nice way.

@calebcartwright
Copy link
Member

Thanks for reaching out @kaikalii!

This is a duplicate of #4031 and has already been fixed. It should be included in the next release of rustfmt, but if you need the fix more urgently you could consider building rustfmt from source in the interim.

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

2 participants