From b754b334e078637f84ae4c20f874b221352ba21f Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Sat, 2 Sep 2023 20:08:50 -0600 Subject: [PATCH] do not combine if multiple exprs of the same kind --- src/doc/style-guide/src/expressions.md | 45 +++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/doc/style-guide/src/expressions.md b/src/doc/style-guide/src/expressions.md index a88404e87fb17..732897af8208f 100644 --- a/src/doc/style-guide/src/expressions.md +++ b/src/doc/style-guide/src/expressions.md @@ -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