rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.06k stars 892 forks source link

Block comment inside match adds unnecessary comma #6373

Open mfarberbrodsky opened 1 month ago

mfarberbrodsky commented 1 month ago

Using rustfmt 1.7.1-stable (eeb90cda 2024-09-04), In the following example:

fn main() {
    let x: Option<i32> = Some(10);
    let value = match x {
        Some(i) => i /* comment */,
        None => 0
    };
    println!("{}", value);
}

Rustfmt adds an additional comma before the block comment, which causes the following error:

error: expected pattern, found `,`
 --> src/test.rs:4:36
  |
4 |         Some(i) => i, /* comment */,
  |                                    ^ expected pattern

error: aborting due to 1 previous error
mfarberbrodsky commented 1 month ago

Hey, I debugged the issue and opened a PR to fix it. Will be happy to respond to any comments. Cheers!