Skip to content

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

Closed
@Samzyre

Description

@Samzyre

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions