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

Formatting of associated types with GATs very verbose #6387

Open
nicoburns opened this issue Nov 7, 2024 · 1 comment
Open

Formatting of associated types with GATs very verbose #6387

nicoburns opened this issue Nov 7, 2024 · 1 comment

Comments

@nicoburns
Copy link

nicoburns commented Nov 7, 2024

This relates to #5887

This change is making a number of associated type implementations in my codebase that were previously a single line (and fit within the 100 character limit) now take up 4 lines. And I am concerned that the new formatting will make it harder for me to justify including associated types in my code due to the verbosity it imposes both on my own codebase and on implementors of traits I create.

As an example:

    type GridItemStyle<'a> = &'a Style where Self: 'a;

is now

    type GridItemStyle<'a>
        = &'a Style
    where
        Self: 'a;

This seems incredibly unfortunate as I find that associated types are generally implementation details that one wants to keep "out of the way" rather than emphasising in the code. In fact, I often don't want to have an associated type at all, it's just required to keep the API flexible. In particular:

  • There seems to be no need to split the name and value onto separate lines when they fit on one line. For let bindings and function definitions we have a smart heuristic based on line length. I think we could do the same here.
  • the where Self: 'a is boilerplate code that conveys no useful information. I think it would be better if it was hidden off the end of the line if possible, or else taking up a single line if not.

Proposal

I concede that where clauses are typically formatted onto separate lines in Rust, but I think that where Self: 'a could be special cased to some degree. So I would propose:

The entirely single line form is used if the full line fits within the width limit:

    type GridItemStyle<'a> = &'a Style where Self: 'a;

Else the following form is used if the definition minus the where clause fits within the width limit:

    type GridItemStyle<'a> = &'a Style
    where
        Self: 'a;

And finally the existing form is used as a last resort if the width limit is exceeded by just the type part of the definition:

    type GridItemStyle<'a>
        = &'a Style
    where
        Self: 'a;
@ytmimi
Copy link
Contributor

ytmimi commented Nov 7, 2024

To change the default style rules you'd need to reach out to the style-team. The current behavior is an implementation of the rules outlined in the Rust Style Guilde.

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

No branches or pull requests

2 participants