Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Kijewski opened this issue May 15, 2025 · 2 comments
Closed

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

Kijewski opened this issue May 15, 2025 · 2 comments
Labels
a-macros bug Panic, non-idempotency, invalid code, etc. duplicate

Comments

@Kijewski
Copy link

Kijewski commented May 15, 2025

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:

@ZaneErebos
Copy link

I am having the same issue: #6563

It seems that it indents by 2*tab_spaces everytime up until max_width

@workingjubilee
Copy link
Member

@rustbot transfer rustfmt

@rustbot rustbot transferred this issue from rust-lang/rust May 16, 2025
@ytmimi ytmimi closed this as completed Jun 5, 2025
@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. duplicate a-macros and removed C-bug needs-triage labels Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-macros bug Panic, non-idempotency, invalid code, etc. duplicate
Projects
None yet
Development

No branches or pull requests

5 participants