Skip to content

Separate function parameter from its attributes by a newline #6276

Open
@Veetaha

Description

@Veetaha

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,
) {
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions