Skip to content

Commit b754b33

Browse files
committed
do not combine if multiple exprs of the same kind
1 parent 75d207a commit b754b33

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

Diff for: src/doc/style-guide/src/expressions.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,51 @@ let x = func(an_expr, another_expr, SomeStruct {
850850

851851
Apply this behavior recursively.
852852

853+
```rust
854+
foo(an_expr, bar(another_expr, SomeStruct(SomeEnum::Variant {
855+
field: this_is_long,
856+
another_field: 123,
857+
})));
858+
859+
Thing(an_expr, do_something_with(another_expr, [
860+
one,
861+
two,
862+
three,
863+
]));
864+
```
865+
866+
Do not apply the combining behavior if one of the prior arguments is the
867+
same kind of expression as the last argument.
868+
869+
```rust
870+
// The `[h, v + 0.1, 0.0]` sub-array is not combinable, because
871+
// there is a previous sub-array in the outer array.
872+
func(an_expr, &[
873+
[h - 0.1, v, 0.0],
874+
[h + 0.1, v, 0.0],
875+
[h, v + 0.1, 0.0],
876+
]);
877+
878+
// The `Thing` field struct expression is not combinable, because
879+
// there is a previous field struct expression in the arguments to `run`.
880+
func(an_expr, run(
881+
Foo { x: 1, y: 2, z: 3 },
882+
Bar { x: 1, y: 2, z: 3 },
883+
Thing { x: 1, y: 2, z: 3 },
884+
));
885+
886+
// The `(more_exprs, last_expr)` tuple is not combinable, because
887+
// there is a previous tuple in the array.
888+
func(an_expr, [
889+
(another_expr, third_expr),
890+
(expr_four, fifth_expr),
891+
(more_exprs, last_expr),
892+
]);
893+
```
894+
853895
If the last argument is a multi-line closure with an explicit block,
854-
only apply the combining behavior if there are no other closure arguments.
896+
only apply the combining behavior if there are no other closure arguments,
897+
regardless of whether they have explicit blocks or occupy multiple lines.
855898

856899
```rust
857900
// Combinable

0 commit comments

Comments
 (0)