Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3628783

Browse files
Rollup merge of#119838 - joshtriplett:style-guide-binop-indent, r=compiler-errors
style-guide: When breaking binops handle multi-line first operand betterUse the indentation of the *last* line of the first operand, not the first.Fixesrust-lang/style-team#189
2 parents31026b7 +e098eb1 commit3628783

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

‎src/doc/style-guide/src/editions.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ include:
4040
of a delimited expression, delimited expressions are generally combinable,
4141
regardless of the number of members. Previously only applied with exactly
4242
one member (except for closures with explicit blocks).
43+
- When line-breaking a binary operator, if the first operand spans multiple
44+
lines, use the base indentation of the last line.
4345
- Miscellaneous`rustfmt` bugfixes.
4446
- Use version-sort (sort`x8`,`x16`,`x32`,`x64`,`x128` in that order).
4547
- Change "ASCIIbetical" sort to Unicode-aware "non-lowercase before lowercase".

‎src/doc/style-guide/src/expressions.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,37 @@ foo_bar
328328
Prefer line-breaking at an assignment operator (either`=` or`+=`, etc.) rather
329329
than at other binary operators.
330330

331+
If line-breaking at a binary operator (including assignment operators) where the
332+
first operand spans multiple lines, use the base indentation of the*last*
333+
line of the first operand, and indent relative to that:
334+
335+
```rust
336+
implSomeType {
337+
fnmethod(&mutself) {
338+
self.array[array_indexasusize]
339+
.as_mut()
340+
.expect("thing must exist")
341+
.extra_info=
342+
long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;
343+
344+
self.array[array_indexasusize]
345+
.as_mut()
346+
.expect("thing must exist")
347+
.extra_info
348+
+long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;
349+
350+
self.array[array_indexasusize]
351+
.as_mut()
352+
.expect("thing must exist")
353+
.extra_info=Some(ExtraInfo {
354+
parent,
355+
count:countasu16,
356+
children:children.into_boxed_slice(),
357+
});
358+
}
359+
}
360+
```
361+
331362
###Casts (`as`)
332363

333364
Format`as` casts like a binary operator. In particular, always include spaces

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp