rust-lang / rust-lang/rustfmt

Separate function parameter from its attributes by a newline

Open
#6,276 6 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Context

Hi, I'm the author of the crate bon. It exposes a proc macro that generates a builder for a function. Every function parameter can be configured with additional #[builder(...)] options.

Problem

For example, this function declares 4 parameters, two of which are optional (they have default values). As for me, the way rustfmt formatted this code doesn't look nice:

#[bon::builder]
fn example(
    #[builder(default = 1)] foo: u32,
    bar: u32,
    #[builder(default = 3)] baz: u32,
    fizz: u32,
) {
}

The attribute on the function's parameter was formatted on the same line with the parameter itself, even though the signature of the function already takes up multiple lines. It is harder to read the signature this way because names of function parameters aren't aligned

I'd expect the following formatting for this example of code instead:

#[bon::builder]
fn example(
    #[builder(default = 1)]
    foo: u32,
    bar: u32,
    #[builder(default = 3)]
    baz: u32,
    fizz: u32,
) {
}

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

Reproduce the issue using the Rust function examples in the report, then trace rustfmt's parameter and attribute formatting entry points. Done means multiline signatures place each parameter attribute on its own line before the parameter, matching the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.