Skip to content

Commit

Permalink
syle-guide: Clarify let-else further
Browse files Browse the repository at this point in the history
Give some additional examples with multi-line patterns.

Make it clearer to go on to the next case if the conditions aren't met.
  • Loading branch information
joshtriplett committed Jun 28, 2023
1 parent eb76764 commit 5abeb80
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/doc/style-guide/src/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ before the `else`.

If the initializer expression is multi-line, the `else` keyword and opening
brace of the block (i.e. `else {`) should be put on the same line as the end of
the initializer expression, with a space between them, if all the following are
true:
the initializer expression, with a space between them, if and only if all the
following are true:

* The initializer expression ends with one or more closing
parentheses, square brackets, and/or braces
Expand Down Expand Up @@ -209,6 +209,28 @@ fn main() {
else {
return;
};

let LongStructName(AnotherStruct {
multi,
line,
pattern,
}) = slice.as_ref()
else {
return;
};

let LongStructName(AnotherStruct {
multi,
line,
pattern,
}) = multi_line_function_call(
arg1,
arg2,
arg3,
arg4,
) else {
return;
};
}
```

Expand Down

0 comments on commit 5abeb80

Please sign in to comment.