rust-lang / rust-lang/rustfmt

Different indentation with single-bound and multi-bounds

Open
#4,731 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-bounds A-whitespace C-bug I-poor-formatting I-vertical-alignment
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Input

fn f1() -> Box<
    FnMut1() -> Thing1<
        WithType = LongItemName,
        Error = LONGLONGLONGLONGLONGONGEvenLongerErrorNameLongerLonger,
    >,
> {
}
fn f2() -> Box<
    FnMu2t() -> Thing2<
            WithType = LongItemName,
            Error = LONGLONGLONGLONGLONGONGEvenLongerErrorNameLongerLonger,
        > + fmt::Write,
> {
}

Output
Same as input.

Expected output
In the above example, Thing1 and Thing2 internal indentation is different because of the addition of the second bound fmt::Write to FnMu2t().

It is not clear which of these indentations is the required indentation, as the guidelines for different cases are not clear. For example, the following where formatted code has the same issue:

fn foo<F>(foo2: F)
where
    F: Fn1(
        // this comment is deleted
    )
{
}
fn foo<F>(foo2: F)
where
    F: Fn2(
            // this comment is deleted
        ) + fmt::Write
{
}

On the other hand, the following formatted impl example is different:

fn build_sorted_static_get_entry_names(
    mut entries: entry,
) -> (
    impl Fn(
        AlphabeticalTraversal,
        Seconddddddddddddddddddddddddddddddddddd,
    ) -> Parammmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
    + Sendddddddddddddddddddddddddddddddddddddddddddd
) {
}

Note that in the where example with a second bound, the closing parenthesis ) is not indented the same as the F of F: Fn2, while in the impl example the ) is under the impl of impl Fn. Although these are different cases, it seems that the formatting guidelines are different.

Is it o.k. that the indentation is changed when a second bound is added? If not, what is the expected output in the above examples?

Meta

  • rustfmt version: rustfmt 2.0.0-rc.2-nightly (32e3ee90 2021-03-01)
  • From where did you install rustfmt?: self build

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 reported single-bound, multi-bound, where-clause, and impl examples with the stated rustfmt 2.0.0-rc.2-nightly version. Compare the current output with the expected indentation and determine whether the project has an established rule for these cases; done means the intended behavior is clarified and the relevant formatting behavior is made consistent or documented.

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
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.