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

if-let guard formatting #4955

Closed
LeSeulArtichaut opened this issue Aug 13, 2021 · 4 comments
Closed

if-let guard formatting #4955

LeSeulArtichaut opened this issue Aug 13, 2021 · 4 comments
Labels
blocked Blocked on rustc, an RFC, etc.

Comments

@LeSeulArtichaut
Copy link

if let guard formatting seems to be unsupported in rustfmt:

// This isn't rewritten
fn main() {
    match foo {
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if let Some(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) = ccccccccccccccccccccccccccccccccccccccccccccccccc => {}
    }
}

cc rust-lang/rfcs#2294 rust-lang/rust#51114

@calebcartwright
Copy link
Member

Thanks for the report.

For anyone that takes a pass at working on this, please note that the length isn't an issue; the root issue i's a complete lack of handling the construct in the AST nodes.

@Nadrieril
Copy link
Member

Nadrieril commented May 15, 2023

I understand that this issue is blocked on deciding how these should be formatted. However, the main problem for me rn is that when I use an if-let guard, the whole body of the arm stays unformatted (tried with whichever rustfmt is run with ./x.py fmt on rustc master).

Whaveter the final style decision for how to format the if let, the body will get formatted the same way. So this shouldn't be independent from any style decision. Is this doable?

@calebcartwright
Copy link
Member

Whaveter the final style decision the body will get formatted the same way so this shouldn't be blocked on anything

That's an incorrect assumption. The nature of the arm pattern and guard formatting directly influence how the body is formatted, as dictated by the Style Guide. It's unfortunate from an end user perspective, but there's various cases where if rustfmt cannot format some sub part of an AST node, then it results in it not being able to format the entire AST node itself.

Is this doable?

No. But formatting support for let expressions isn't too terribly far off

@ytmimi
Copy link
Contributor

ytmimi commented Dec 16, 2023

Closing as support for this was added in #5910

On the latest rustfmt master we now format the input:

input:

fn main() {
    match foo {
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if let Some(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) = ccccccccccccccccccccccccccccccccccccccccccccccccc => {}
    }
}

output:

fn main() {
    match foo {
        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
            if let Some(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) =
                ccccccccccccccccccccccccccccccccccccccccccccccccc => {}
    }
}

@ytmimi ytmimi closed this as completed Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Blocked on rustc, an RFC, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants