rust-lang / rust-lang/rustfmt

Supertraits are wrapped at less than `max_width` (sometimes 20+ chars less)

Open
#6,809 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug S-has-mcve SO-max_width
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

If I format this code with max_width = 50:

// line below is 30 chars
pub(super) unsafe trait A: B {
    fn foo();
}

// line below is 36 chars
pub unsafe trait Trait2: A + B + C {
    fn foo();
}

// line below is 43 chars
pub trait TraitThree: Super1 + Super2 + X {
    fn foo();
}

// line below is 47 chars
trait TraitNumberFour: Super1 + Super2 + Abcd {
    fn foo();
}

// line below is correctly not wrapped
pub const THIS_LINE_IS_50_CHARS: usize = 12345678;

I get this:

// line below is 30 chars
pub(super) unsafe trait A:
    B
{
    fn foo();
}

// line below is 36 chars
pub unsafe trait Trait2:
    A + B + C
{
    fn foo();
}

// line below is 43 chars
pub trait TraitThree:
    Super1 + Super2 + X
{
    fn foo();
}

// line below is 47 chars
trait TraitNumberFour:
    Super1 + Super2 + Abcd
{
    fn foo();
}

// line below is correctly not wrapped
pub const THIS_LINE_IS_50_CHARS: usize = 12345678;

All of the supertraits were moved to a separate line even though none of the original lines exceeded the max width.

The same thing happens with other values of max_width, including the default of 100.

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

No source file or test is named. Reproduce the examples with max_width values of 50 and 100, then trace the formatter's supertrait wrapping behavior. Done means lines that already fit within max_width remain unwrapped, with regression coverage for the shown trait declarations.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.