rust-lang / rust-lang/rustfmt

Handle function-like attribute macros with generic types in them

Open
#6,680 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When using an attribute macro with a function-like syntax:

#[my_macro(Item1, Item2, Item3)]
fn my_fun() {}

rust fmt can give up if the arguments to the macro are types with generic parameters. If the macro line is too long and should be rewritten in several lines, rust fmt doesn't handle the situation at all:

#[my_macro(Item1<u32>, Item2<u32>, Item3<u32>, Item4<u32>, Item5<u32>, Item6<u32>)]
fn my_fun() {}

Workaround: using an alias for those types to not have to write generic parameters in the macro arguments.

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.

Research direction

Start by reproducing the issue with the #[my_macro(...)] examples, including generic type arguments and a line long enough to require rewriting. Trace rustfmt's handling of function-like attribute macro arguments and verify that the long macro invocation is formatted across multiple lines without changing its contents.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.