Skip to content

How Should Formatters Add Line Breaks for Long Type Alias Bounds #193

Open
@ytmimi

Description

@ytmimi

This is related to rust-lang/rustfmt#5892. To summarize, there are inconsistencies when formatting Type Alias Bounds with rustfmt when using different style_edition values.

Using style_edition={2015|2018|2021} produces the following output:

type AAAAAAAAAAAAA: BBBBBBBBBBBBBBB<
    CCCCCCCCCCCCCCCCC,
    DDDDDDDDDDDDDDDDD,
    EEEEEEEEEEEEEEEEE,
    FFFFFFFFFFFFFFFFF,
    GGGGGGGGGGGGGGGGG,
    HHHHHHHHHHHHHHHHH,
    IIIIIIIIIIIIIIIII,
>;

and using style_edition=2024 produces the following output:

type AAAAAAAAAAAAA: BBBBBBBBBBBBBBB<
        CCCCCCCCCCCCCCCCC,
        DDDDDDDDDDDDDDDDD,
        EEEEEEEEEEEEEEEEE,
        FFFFFFFFFFFFFFFFF,
        GGGGGGGGGGGGGGGGG,
        HHHHHHHHHHHHHHHHH,
        IIIIIIIIIIIIIIIII,
    >;

The Type Alias Section of the Style Guide, doesn't give any prescription for how to break or handle the indentation of the bounds.

In rust-lang/rustfmt#6293, it was suggested that the Type Alias Bounds should be similar to those for Trait Bounds, and therefore produce the following formatting:

type AAAAAAAAAAAAA:
    BBBBBBBBBBBBBBB<
        CCCCCCCCCCCCCCCCC,
        DDDDDDDDDDDDDDDDD,
        EEEEEEEEEEEEEEEEE,
        FFFFFFFFFFFFFFFFF,
    >;

So I'm wondering what the correct formatting should be, and if the Style Guide should be updated to provide clearer guidance on this.

Another question I have is how should Type Alias Bounds be formatted in this following case:

// This is the formatting rustfmt produces for all style editions
type AAAAAAAAAAAAA: BBBBBBBBBBBBBBB<
        CCCCCCCCCCCCCCCCC,
        DDDDDDDDDDDDDDDDD,
        EEEEEEEEEEEEEEEEE,
        FFFFFFFFFFFFFFFFF,
        GGGGGGGGGGGGGGGGG,
        HHHHHHHHHHHHHHHHH,
        IIIIIIIIIIIIIIIII,
    > + Copy
    + Debug;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions