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

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

Closed
anatawa12 opened this issue Feb 8, 2025 · 1 comment · Fixed by #6468
Closed
Labels
good first issue Issues up for grabs, also good candidates for new rustfmt contributors

Comments

@anatawa12
Copy link
Contributor

anatawa12 commented Feb 8, 2025

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)
@ytmimi
Copy link
Contributor

ytmimi commented Feb 10, 2025

Thanks for the report! I didn't even realize you could add a label to a closure's block body. Should be easy enough to fix if we pass the entire block expression (body) to rewrite_closure_block instead of just the block. The block doesn't have information about the label.

rewrite_closure_block(block, &prefix, context, body_shape)

- rewrite_closure_block(block, &prefix, context, body_shape)
+ rewrite_closure_block(body, &prefix, context, body_shape) 

@ytmimi ytmimi added the good first issue Issues up for grabs, also good candidates for new rustfmt contributors label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues up for grabs, also good candidates for new rustfmt contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants