Skip to content

rustfmt keeps indenting macro definitions' bodies in macro definitions #4111

Closed
@Dashurai

Description

@Dashurai

With the following input (the a macro is for showing the behaviour with multiple macros and a different initial formatting) :

pub macro scalar($m: ident, $t: ident) {
    pub macro $m {
        () => {Val::$t($t::default())},
        ($v: expr) => {Val::$t($t::new($v))}
    }
    pub macro a {
        () => {
            Val::$t($t::default())
        },
        ($v: expr) => {
            Val::$t($t::new($v))
        }
    }
}

A pass of rustfmt adds a level of indentation to the inner macros' bodies, including the closing bracket :

pub macro scalar($m: ident, $t: ident) {
    pub macro $m {
            () => {Val::$t($t::default())},
            ($v: expr) => {Val::$t($t::new($v))}
        }
    pub macro a {
            () => {
                Val::$t($t::default())
            },
            ($v: expr) => {
                Val::$t($t::new($v))
            }
        }
}

And it keeps adding a level at each run. This also triggers cargo watch.
It seems very similar to #2588 but this one is fixed.
Version rustfmt 1.4.13-nightly (c126730 2020-03-31), run within cargo watch with no parameter (cargo watch -x fmt -x run --no-gitignore --clear -q).

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-macrosbugPanic, non-idempotency, invalid code, etc.only-with-optionrequires a non-default option value to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions