Skip to content

Commit

Permalink
do not combine if multiple exprs of the same kind
Browse files Browse the repository at this point in the history
  • Loading branch information
pitaj committed Sep 3, 2023
1 parent 75d207a commit b754b33
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/doc/style-guide/src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,51 @@ let x = func(an_expr, another_expr, SomeStruct {

Apply this behavior recursively.

```rust
foo(an_expr, bar(another_expr, SomeStruct(SomeEnum::Variant {
field: this_is_long,
another_field: 123,
})));

Thing(an_expr, do_something_with(another_expr, [
one,
two,
three,
]));
```

Do not apply the combining behavior if one of the prior arguments is the
same kind of expression as the last argument.

```rust
// The `[h, v + 0.1, 0.0]` sub-array is not combinable, because
// there is a previous sub-array in the outer array.
func(an_expr, &[
[h - 0.1, v, 0.0],
[h + 0.1, v, 0.0],
[h, v + 0.1, 0.0],
]);

// The `Thing` field struct expression is not combinable, because
// there is a previous field struct expression in the arguments to `run`.
func(an_expr, run(
Foo { x: 1, y: 2, z: 3 },
Bar { x: 1, y: 2, z: 3 },
Thing { x: 1, y: 2, z: 3 },
));

// The `(more_exprs, last_expr)` tuple is not combinable, because
// there is a previous tuple in the array.
func(an_expr, [
(another_expr, third_expr),
(expr_four, fifth_expr),
(more_exprs, last_expr),
]);
```

If the last argument is a multi-line closure with an explicit block,
only apply the combining behavior if there are no other closure arguments.
only apply the combining behavior if there are no other closure arguments,
regardless of whether they have explicit blocks or occupy multiple lines.

```rust
// Combinable
Expand Down

0 comments on commit b754b33

Please sign in to comment.