rust-lang / rust-lang/rustfmt

rustfmt puts `where` on same line as `impl` for empty `impl` even if long

Open
#5,811 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

I-poor-formatting S-blocked X-requires-next-style-edition
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Given the following code:

impl<T: ?Sized, Idx> IndexRanges<Idx> for T
where
    T: Index<Range<Idx>, Output = Self::Output>
        + Index<RangeTo<Idx>, Output = Self::Output>
        + Index<RangeFrom<Idx>, Output = Self::Output>
        + Index<RangeInclusive<Idx>, Output = Self::Output>
        + Index<RangeToInclusive<Idx>, Output = Self::Output>
        + Index<RangeFull>,
{
}

rustfmt moves the where onto the same line as the impl. However, if you put a fn func() {} inside, it won't.

This may need to wait for a style edition to fix.

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

Start by reproducing the issue with the empty and non-empty impl examples in the report, then trace rustfmt's handling of impl blocks and where clauses. Done means the empty impl follows the intended line-breaking behavior without changing the non-empty case, with coverage for the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.