Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style-guide: Clarify grammar for small patterns (not a semantic change) #113384

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/doc/style-guide/src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,9 @@ not put the `if` clause on a newline. E.g.,
}
```

If every clause in a pattern is *small*, but does not fit on one line, then the
pattern may be formatted across multiple lines with as many clauses per line as
possible. Again break before a `|`:
If every clause in a pattern is *small*, but the whole pattern does not fit on
one line, then the pattern may be formatted across multiple lines with as many
clauses per line as possible. Again break before a `|`:

```rust
foo | bar | baz
Expand All @@ -763,17 +763,18 @@ possible. Again break before a `|`:
}
```

We define a pattern clause to be *small* if it matches the following grammar:
We define a pattern clause to be *small* if it fits on a single line and
matches "small" in the following grammar:

```
[small, ntp]:
- single token
- `&[single-line, ntp]`
small:
- small_no_tuple
- unary tuple constructor: `(` small_no_tuple `,` `)`
- `&` small

[small]:
- `[small, ntp]`
- unary tuple constructor `([small, ntp])`
- `&[small]`
small_no_tuple:
- single token
- `&` small_no_tuple
```

E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.
Expand Down