Skip to content

Formatting struct with trailing comment is not idempotent #4848

Closed as not planned
@gkanwar

Description

@gkanwar

I am working with with trailing_comma = "Never" set in a rustfmt.toml config, running the nightly rustfmt, and find the following idempotency issue. My understanding is that instead of the following behavior, rustfmt should fully format the code once and not change on future executions.

Starting with the code:

struct Foo {
    field1: usize,
    field2: usize,
    // TODO: maybe we add more fields below
}

Calling rustfmt the first time gives

struct Foo {
    field1: usize,
    field2: usize
    // TODO: maybe we add more fields below
}

Calling rustfmt the second time gives

struct Foo {
    field1: usize,
    field2: usize // TODO: maybe we add more fields below
}

All subsequent calls leave it in this final state.

My rustfmt version is rustfmt 1.4.37-nightly (8cf990c 2021-05-15)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions