Skip to content

rustfmt requires two runs to converge on contrived input #6437

Open
@jrose-signal

Description

@jrose-signal
fn test(input: Foo) {
    match input {
        Foo::Bar => {
            ;
            Baz {
                field: 0
            }
        }
    }
}

Given this admittedly contrived input, running rustfmt once removes the semicolon. Running it a second time removes the braces for the match body.

I don't know if rustfmt has a rule about being idempotent, but it certainly would surprise me to regularly encounter situations where I have to manually run it to a fixed point.

Tested in the playground, 1.8.0-stable (2024-11-26 90b35a6239).

Activity

ytmimi

ytmimi commented on Jan 6, 2025

@ytmimi
Contributor

Yes, the output should be idempotent. Thanks for reporting this!

ytmimi

ytmimi commented on Jan 6, 2025

@ytmimi
Contributor

Related to #6116, but I'm not sure if this is a duplicate.

added
bugPanic, non-idempotency, invalid code, etc.
on Jan 6, 2025
mu001999

mu001999 commented on Jan 9, 2025

@mu001999
Contributor

I tested and this can be fixed by #6128, so this is a duplicate

ytmimi

ytmimi commented on Jan 23, 2025

@ytmimi
Contributor

From what I can tell, #6128 doesn't resolve this, though the fix might be something similar.

Formatting the input produces:

fn test(input: Foo) {
    match input {
        Foo::Bar => {
            Baz { field: 0 }
        }
    }
}

And formatting the snippet above outputs:

fn test(input: Foo) {
    match input {
        Foo::Bar => Baz { field: 0 },
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mu001999@ytmimi@jrose-signal

        Issue actions

          rustfmt requires two runs to converge on contrived input · Issue #6437 · rust-lang/rustfmt