Skip to content

Formatting a macro that generates a struct with a field with a multiline attribute adds indentation forever #5489

Open
@shepmaster

Description

@shepmaster
macro_rules! generate_the_struct {
    ($a:literal) => {
        pub struct Struct {
            #[clap(
                long = "--alpha-beta-gamma",
                env = "ALPHA_BETA_GAMMA",
                default_value = $a,
            )]
            alpha_beta_gamma: usize,
        }
    };
}

The arguments of the clap attribute will be indented for every call to cargo fmt. For example...

% for x in $(seq 10); do cargo fmt; done
% git diff
diff --git a/src/main.rs b/src/main.rs
index 1f1a25c..c1dee62 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,10 +2,10 @@ macro_rules! generate_the_struct {
     ($a:literal) => {
         pub struct Struct {
             #[clap(
-                long = "--alpha-beta-gamma",
-                env = "ALPHA_BETA_GAMMA",
-                default_value = $a,
-            )]
+                                                                        long = "--alpha-beta-gamma",
+                                                                        env = "ALPHA_BETA_GAMMA",
+                                                                        default_value = $a,
+                                                                    )]
             alpha_beta_gamma: usize,
         }
     };

This occurs with:

  • rustfmt 1.4.38-stable (e092d0b6 2022-07-16)
  • rustfmt 1.5.1-nightly (f6f9d5e7 2022-08-04)

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