Skip to content

Rustfmt Unconditionally Indents Code Each Time It's Run #2607

Closed
@bheisler

Description

@bheisler

This is an odd bug I found while running rustfmt on Criterion.rs.

Steps to reproduce:

  • cargo init rustfmt-test
  • Create a benches directory (this doesn't happen if the code is in src)
  • Create a file named test.rs in the benches directory with the following code:
macro_rules! bench {
    ($ty:ident) => {
        criterion_group!(
            name = benches;
            config = ::common_bench::reduced_samples();
            targets = call, map;
        );
    };
}
  • Run cargo +nightly fmt. Code now looks like this:
macro_rules! bench {
    ($ty:ident) => {
        criterion_group!(
                    name = benches;
                    config = ::common_bench::reduced_samples();
                    targets = call, map;
                );
    };
}
  • Run cargo +nightly fmt again. Code now looks like this:
macro_rules! bench {
    ($ty:ident) => {
        criterion_group!(
                            name = benches;
                            config = ::common_bench::reduced_samples();
                            targets = call, map;
                        );
    };
}

It always adds another 8 spaces before those four lines. I haven't been able to find a workaround for this (though if you find one, please let me know so I can re-enable my rustfmt Travis-CI build).

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-macrosbugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions