Skip to content

rustfmt: formatting meta-arguments in a macro is not idempotent #6565

Open
@Kijewski

Description

@Kijewski

Given this source:

macro_rules! new_greeter {
    () => {
        #[template(
            add = some::tokens,
            to = make::the::line::longer
        )]
        struct X;
    };
}

Call cargo fmt (tested with +stable = 1.87.0 and +nightly = 1.89.0-nightly (056f5f4f3 2025-05-09)).

The indentation level of add = ... )] is incremented by 8 spaces for every fmt invocation until the 100 character line limit is hit.

Source after multiple `cargo fmt` calls (click me)
macro_rules! new_greeter {
    () => {
        #[template(
                    add = some::tokens,
                    to = make::the::line::longer
                )]
        struct X;
    };
}
macro_rules! new_greeter {
    () => {
        #[template(
                            add = some::tokens,
                            to = make::the::line::longer
                        )]
        struct X;
    };
}
macro_rules! new_greeter {
    () => {
        #[template(
                                                                    add = some::tokens,
                                                                    to = make::the::line::longer
                                                                )]
        struct X;
    };
}

I would have assumed that cargo fmt is idempotent, i.e. that calling after calling it once the code remains unchanged. (IHMO my example code does not need reformatting in any case.)

It can be tested on the playground, too:

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