rust-lang / rust-lang/rustfmt

In macros invocation, a comma is inserted after struct/enum declaration

Open
#4,375 3 comments 0 reactions 1 assignee View on GitHub

@topecongiro is already working on this.

Since Aug 9, 2020.

A-macros C-bug I-poor-formatting
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

TLDR: a , is inserted between struct/enum declaration and other fragment specifiers in macros, which cause them to break after formatting.

This happens for both tupled and named structs and enums, but does not happen for unions. This is clearly not linked to the macro definition itself.

Input

mac!(struct Foo {} bar);
mac!(struct Foo; bar);
mac!(enum Foo {} bar);

Output

mac!(struct Foo {}, bar);
mac!(struct Foo;, bar);
mac!(enum Foo {}, bar);

Notice the , inserted between the struct/enum declaration, which can break the macro.

Expected output

mac!(struct Foo {} bar);
mac!(struct Foo; bar);
mac!(enum Foo {} bar);

I have created a playground link, so that it is easier to see what's wrong.

Meta

  • rustfmt version: rustfmt 1.4.15-stable (530eadf 2020-06-02) (tested, also reproducible on the playground)
  • From where did you install rustfmt?: Installed via NixOS package manager, but also happens on the playground.

Feel free to ping me if other information is needed.

Edits

  • 2020/08/27: specify that this is independent from the macro definition itself, mention enums and unions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.