Skip to content

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

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
bheisler opened this issue Apr 8, 2018 · 3 comments · Fixed by #2775
Closed

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

bheisler opened this issue Apr 8, 2018 · 3 comments · Fixed by #2775
Labels
a-macros bug Panic, non-idempotency, invalid code, etc.

Comments

@bheisler
Copy link

bheisler commented Apr 8, 2018

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).

@topecongiro topecongiro added bug Panic, non-idempotency, invalid code, etc. a-macros labels Apr 8, 2018
@topecongiro
Copy link
Contributor

A workaround could be to use {} over () for macro call:

macro_rules! bench {
    ($ty:ident) => {
-        criterion_group!(
+        criterion_group!{
            name = benches;
            config = ::common_bench::reduced_samples();
            targets = call, map;
-        );
+        };
    };
}

@bheisler
Copy link
Author

bheisler commented Apr 8, 2018

Great, thanks! That works just fine as a workaround.

@Amanieu
Copy link
Member

Amanieu commented Apr 8, 2018

Possible duplicate of #2588?

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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants