rust-lang / rust-lang/rustfmt

Multi-line struct field values should begin on the same line

Open
#5,117 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I would like to see struct field values start on the same line as the field name even when the expression takes multiple lines.

Config: version=Two and max_width=50.

Current:

let Struct {
    tuplestruct:
        TupleStruct(
            Foo {
                message: "hi friend",
                array:
                    [
                        loooooooooooooong,
                        loooooooooooooong,
                    ],
            },
            looooooooong,
        ),
    ..
} = x;

Desired:

let Struct {
    tuplestruct: TupleStruct(
        Foo {
            message: "hi friend",
            array: [
                loooooooooooooong,
                loooooooooooooong,
            ],
        },
        looooooooong,
    ),
    ..
} = x;

This draws your attention to the field names more than their values, making it easier to scan the overall structure without getting distracted by the values. Also it can drastically reduce indentation for patterns with a lot of nesting.

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 supplied Rust pattern with rustfmt using Config: version=Two and max_width=50, then inspect the formatter path responsible for struct pattern fields and multiline expressions. Done means the field value begins on the field-name line while preserving the shown wrapping and indentation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.