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 stops working if the comment just after the => of a "match" contains "=>" #5998

Closed
rxdiscovery opened this issue Dec 29, 2023 · 1 comment · Fixed by #6092
Closed
Labels
a-comments a-matches match arms, patterns, blocks, etc

Comments

@rxdiscovery
Copy link

rxdiscovery commented Dec 29, 2023

Hello,

I've noticed that rustfmt stops working if the comment just after the => of a "match" contains "=>".

info :
rustfmt 1.7.0-stable (82e1608 2023-12-21)
rustc 1.75.0 (82e1608df 2023-12-21)

here's an example code :

fn main() {
    let a = 50u32;
    match a {
        10 =>
        // comment => 10
                {
            println!("A")
        }
        20 => {
                            println!("B")
        }
        _ => {
            println!("C")
        }
    }
}

the problem is in the comment :
// comment => 10

the comment contains the symbol "=>", if you try to use rustfmt it won't work.
but if you delete the "=>" from the comment, or simply add a space like this "= >", rustmt works again.

you can test the bug here : ( click on the top-right "Tools -> Rustfmt" button to start formatting, but it won't work as long as the comment contains "=>" )
Playground

Thank you for the wonderful work that you do 👍

@rxdiscovery rxdiscovery changed the title rustfmt stops working if the comment just after the => of a "match" contains "=>". rustfmt stops working if the comment just after the => of a "match" contains "=>" Dec 29, 2023
@ytmimi
Copy link
Contributor

ytmimi commented Dec 29, 2023

@rxdiscovery thanks for the report!

Using rustfmt 1.7.0-nightly (85e21fab 2023-12-28) I can confirm that this first (minimized) example reformats

fn main() {
    match a {
        _ =>
        // any comment here will prevent formatting
                {
            println!("A")
        }
    }
}

while this second example does not.

fn main() {
    match a {
        _ =>
        // comment with =>
                {
            println!("A")
        }
    }
}

@ytmimi ytmimi added a-comments a-matches match arms, patterns, blocks, etc labels Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments a-matches match arms, patterns, blocks, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants