rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Format issue on supertrait with bounds on associated types.

Open gui1117 opened this issue 1 year ago • 6 comments

For all version I could tests (master and nightly)

this code:

pub trait MyLongTraitName:
    MyLongBoundName<
        MyLongAssociatedType:
            SomeAnotherBound<
                YetAnotherType: YetAnotherBound,
                YetAnotherType2: YetAnotherBound2
            >,
        OtherType: SmallBound
            + SmallBound2
            + AnotherLongBound<
                WithSomeType: BeingBound,
                WithSomeType2: BeingBound,
                WithSomeType3: BeingBound
            >
            + SmallBound3
            + AnotherLongBound2<
                WithSomeType: BeingBound,
                WithSomeType2: BeingBound,
                WithSomeType3: BeingBound
            >,
    >
{
}

fn main() {}

gets formatted into:

pub trait MyLongTraitName:
    MyLongBoundName<
    MyLongAssociatedType: SomeAnotherBound<
        YetAnotherType: YetAnotherBound,
        YetAnotherType2: YetAnotherBound2,
    >,
    OtherType: SmallBound
                   + SmallBound2
                   + AnotherLongBound<
        WithSomeType: BeingBound,
        WithSomeType2: BeingBound,
        WithSomeType3: BeingBound,
    > + SmallBound3
                   + AnotherLongBound2<
        WithSomeType: BeingBound,
        WithSomeType2: BeingBound,
        WithSomeType3: BeingBound,
    >,
>
{
}

fn main() {}

gui1117 avatar Sep 08 '24 05:09 gui1117

Thanks for the report. Confirming I can reproduce this the latest master rustfmt 1.7.1-nightly (1a70f40d7f 2024-09-03)

ytmimi avatar Sep 09 '24 15:09 ytmimi

It seems those types are formatted with the overflow formatting, do you suggest to change the overflow formatting or change formatting so it doesn't go into overflow?

gui1117 avatar Sep 10 '24 04:09 gui1117

@gui1117 have you started looking into this issue?

ytmimi avatar Sep 10 '24 16:09 ytmimi

@gui1117 have you started looking into this issue?

Not really, and I would prefer not because I struggle to understand the code. But I look a bit when I have free time.

gui1117 avatar Sep 10 '24 23:09 gui1117

@gui1117 no worries. Based on https://github.com/rust-lang/rustfmt/issues/6316#issuecomment-2339597525 I thought maybe you'd looked through the code.

Not really, and I would prefer not because I struggle to understand the code.

It's quite a tricky part of the codebase. Definitely don't feel obligated to dive in.

ytmimi avatar Sep 11 '24 01:09 ytmimi

Smaller example without any nesting, though I'm sure the nesting doesn't help:

pub trait Example<Inner = ()>:
    ExampleImplementation<
    Inner,
    MoreParam,
    AnotherParam,
    AnotherParamAgain,
    YetAnotherParam,
    AFurtherParam,
>
{
}

jrose-signal avatar Feb 14 '25 19:02 jrose-signal