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

Formatting labelled block expression in match arm causes invalid Rust code #5676

Closed
Samzyre opened this issue Jan 26, 2023 · 0 comments · Fixed by #5677
Closed

Formatting labelled block expression in match arm causes invalid Rust code #5676

Samzyre opened this issue Jan 26, 2023 · 0 comments · Fixed by #5677

Comments

@Samzyre
Copy link

Samzyre commented Jan 26, 2023

This code
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6c806c4f3f7db3d30ba75a53393b222f

fn main() {
    match true {
        true => 'a: {
            break 'a
        }
        _ => (),
    }
}

formats into:

fn main() {
    match true {
        true => break 'a,
        _ => (),
    }
}

So the label is no longer valid.

In this simple case, you could just prevent the formatting by adding a semicolon after the break, but a more complex case might not return () from the labelled block (and therefore require additional changes).

Version:
rustfmt 1.5.2-nightly (c18a5e8a 2023-01-25)

EDIT (@ytmimi): Updated the examples so that rustfmt can be run on the code snippet directly.

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

Successfully merging a pull request may close this issue.

1 participant