Skip to content

rustfmt removes labels of block if inside macro invocation, which will break the code #6465

@anatawa12

Description

@anatawa12

Rustfmt would remove 'block: inside rustfnmt_test0, which will break break 'block Ok(0) line.

For reference, rustfnmt_test1 code won't be broken. this issue only happens with rust.

macro_rules! test_macro {
    (|$transaction: ident| $body: expr) => {{
        let $transaction = some_value;
        let _ = $body;
    }};
}

pub async fn rustfnmt_test0(condition: &bool) {
    test_macro!(|transaction| 'block: {
        if condition {
            break 'block Ok(0);
        }

        todo!()
    });
}

pub async fn rustfnmt_test1(condition: &bool) {
    let x = |transaction| 'block: {
        if condition {
            break 'block Ok(0);
        }

        todo!()
    };
}
rustfmt 1.8.0-beta (0277061b9a 2025-02-01)

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssues up for grabs, also good candidates for new rustfmt contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions