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 rule avoids adding an extra line break when there was room on the same line.
We apply this rule to a series of binops, as well, which gives similarly satisfying results if the first operand is 1-3 characters long:
fnfoo() -> Type{
xxx + longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong
+ more
+ things
+ others
}
However, we use the same 4-character threshold, without taking the space before the binop into account:
fnfoo() -> Type{
xxxx + longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong
+ more
+ things
+ others
}
We only break to a new line when the first item becomes 5 or more characters long.
I think the rule here should be taking the whitespace before the operator into account, such that the threshold is "4 characters (including any space before the binop)".
I think the underlying rule from the style guide here is:
If the length of the last line of the first element plus its indentation is less than or equal to the indentation of the second line, then combine the first and second lines if they fit. Apply this rule recursively.
Worth noting that that rule is only defined for chains:
A chain is a sequence of field accesses, method calls, and/or uses of the try operator ?. E.g., a.b.c().d or foo?.bar().baz?.
I think it's good that we apply this to binops as well, even though we don't have a style guide rule for that. I think we should capture that generalization in the style guide. However, I also think that generalization needs to take into account whether the operator requires spaces around it (like + or -) or does not (like .).
cc @rust-lang/style
The text was updated successfully, but these errors were encountered:
We have a rule that puts the second operand of a chain on the same line as the first if the first is 4 characters or less:
This rule avoids adding an extra line break when there was room on the same line.
We apply this rule to a series of binops, as well, which gives similarly satisfying results if the first operand is 1-3 characters long:
However, we use the same 4-character threshold, without taking the space before the binop into account:
We only break to a new line when the first item becomes 5 or more characters long.
I think the rule here should be taking the whitespace before the operator into account, such that the threshold is "4 characters (including any space before the binop)".
I think the underlying rule from the style guide here is:
Worth noting that that rule is only defined for chains:
I think it's good that we apply this to binops as well, even though we don't have a style guide rule for that. I think we should capture that generalization in the style guide. However, I also think that generalization needs to take into account whether the operator requires spaces around it (like
+
or-
) or does not (like.
).cc @rust-lang/style
The text was updated successfully, but these errors were encountered: