Skip to content

comment inside of empty enum variant payload with explicit discriminant results in invalid syntax after rustfmt run #5686

Closed
@LizzyFleckenstein03

Description

@LizzyFleckenstein03

Example code:

#[repr(u8)]
enum MyEnum {
    MyVariant {
        /* Comment */
    } = 0,
}

This compiles fine.

rustfmt 1.5.2-nightly (50d3ba5 2023-02-04) inserts a line:

#[repr(u8)]
enum MyEnum {
    MyVariant {
        /* Comment */
        } =
    } = 0,
}

This is a syntax error:

error: unexpected closing delimiter: `}`
 --> src/main.rs:7:1
  |
3 |     MyVariant {
  |               - this delimiter might not be properly closed...
4 |         /* Comment */
5 |         } =
  |         - ...as it matches this but it has different indentation
6 |     } = 0,
7 | }
  | ^ unexpected closing delimiter

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-commentsbugPanic, non-idempotency, invalid code, etc.good first issueIssues up for grabs, also good candidates for new rustfmt contributorshelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions