You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
typeGridItemStyle<'a> = &'a StylewhereSelf:'a;
is now
typeGridItemStyle<'a>
= &'a StylewhereSelf:'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:
typeGridItemStyle<'a> = &'a StylewhereSelf:'a;
Else the following form is used if the definition minus the where clause fits within the width limit:
typeGridItemStyle<'a> = &'a StylewhereSelf:'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:
typeGridItemStyle<'a>
= &'a StylewhereSelf:'a;
The text was updated successfully, but these errors were encountered:
The style guide says Keep type aliases on one line when they fit. The rule you linked to has an example that uses the name VeryLongType, indicating this is a rule for a case where it does not fit on one line.
Always breaking associated types like this is quite verbose and results in poorer readability for my uses (CI failure). Is my only option to use rustfmt::skip?
Looking closer, for my use case a lot of those lines are too long, so not sure what to do here.
@philipc At the moment #[rustfmt::skip] is probably your best option since rustfmt doesn't have a configuration option for this. For what it's worth, I questioned the formatting back in #5887 (comment), and it seems that the text about trailing where clauses supersedes any rules about formatting type aliases on one line when they fit. At least that's how I think the text is meant to be interpreted based on @compiler-errors's response.
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:
is now
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:
let
bindings and function definitions we have a smart heuristic based on line length. I think we could do the same here.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 thatwhere 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:
Else the following form is used if the definition minus the where clause fits within the width limit:
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:
The text was updated successfully, but these errors were encountered: