Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ytmimi opened this issue Sep 4, 2024 · 2 comments
Open

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

ytmimi opened this issue Sep 4, 2024 · 2 comments

Comments

@ytmimi
Copy link

ytmimi commented Sep 4, 2024

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;
@calebcartwright
Copy link
Member

Just as a reference to another section of the guide that may be operative here: https://doc.rust-lang.org/nightly/style-guide/types.html#line-breaks

@calebcartwright
Copy link
Member

this was the sole topic we discussed in the t-style meeting today and it was one we discussed at length

Given the pending deadlines for the 2024 Edition work, our position is that for now, the second example:

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

can be considered correct and we're pleased that the formatting is no longer dependent upon the presence/absence of additional bounds (as it was in 2021 and below style editions)

based on the discussion though, it's very conceivable that we'd want to do something different for the next style edition so because of that as well as the desire to start freezing the 2024 edition, we're not going to update the style guide text at this time

please feel free to weigh in and correct me @rust-lang/style but wanted to post a summary to unlock the rustfmt team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants