Add style guide for default field values#149423
Add style guide for default field values#149423agraven wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
Some changes occurred in src/doc/style-guide cc @rust-lang/style |
|
r? @traviscross rustbot has assigned @traviscross. Use |
0fb8104 to
221138d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
The example changed to break before the `=`, but the text still said "after"; fix it to say "before the =".
| does not not fit within the right margin, split the line before the =. Also apply | ||
| a block indent if this was not already done by pulling down the type. |
There was a problem hiding this comment.
| does not not fit within the right margin, split the line before the =. Also apply | |
| a block indent if this was not already done by pulling down the type. | |
| does not not fit within the right margin, split the line before the = and indent one level further before the `=`. |
We talked about this in the style team call today. For my part, I'd like the indentation of the expression to be more regular -- i.e., I don't want to indent the expression further in this context-dependent way. We confront questions similar to this elsewhere in the language. E.g., for conditionals with long conditionals, we write: if long_cond
&& long_other_cond
{
body
}And not: if long_cond
&& long_other_cond
{ body }Similarly, we write: let Some(
long_pattern
) = expr;With guard patterns, we'll even be writing: let Some(
long_pattern if some_long_guard_expr
) = expr;In each of these cases, we don't indent the expression or body further. This makes sense. The expression is not a subitem of the pattern (or for default field values, the type), which is what such indentation would imply. It's a sibling. Therefore I'd expect sibling-level indentation. Wrapping before the struct Foo {
a: A,
b: B
= long_expr,
long_name:
LongType<
LongItem
= SomeType,
>
= long_expr,
}In keeping with what we do for other closing delimiters, we could also imagine doing: struct Foo {
a: A,
b: B
= long_expr,
long_name:
LongType<
LongItem
= SomeType,
> = long_expr,
}Where we left this, in the meeting, was trying to think of whether there was anything else we could do here, other than indentation, to make this more clear. We'll pick this back up in our next meeting. |
Tracking issue: #132162
See in particular rust-lang/style-team#205.