rust-lang / rust-lang/rustfmt

Poor line breaking of multi-item type parameter bounds featuring bracketed generic arguments

Open
#3,599 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This is how rustfmt formats a long list of type parameter bounds featuring a long list of bracketed generic arguments:

    type ProposeTransactionsFuture: Future<
            Item = ProposeTransactionsResponse<Self::MessageId>,
            Error = Error,
        > + Send
        + 'static;

The first bound after the closing bracket is formatted inline and is visually obscured.
It would be better to break and align the top-level + separators:

    type ProposeTransactionsFuture: Future<
            Item = ProposeTransactionsResponse<Self::MessageId>,
            Error = Error,
        >
        + Send
        + 'static;

Edit: Or better yet, on suggestion by @topecongiro below:

    type ProposeTransactionsFuture:
        Future<
            Item = ProposeTransactionsResponse<Self::MessageId>,
            Error = Error,
        >
        + Send
        + 'static;

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 Rust formatting example from the issue and trace rustfmt's handling of type parameter bounds and nested generic arguments. Identify the relevant formatting entry point and regression-test location, then make the top-level + separators break and align as shown in the preferred example.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.