Skip to content

Commit c668eb0

Browse files
authored
Rollup merge of #113384 - joshtriplett:style-guide-grammar, r=compiler-errors
style-guide: Clarify grammar for small patterns (not a semantic change) The grammar as written feels ambiguous and confusing, in large part because it uses square brackets and commas in the names of non-terminals. Rewrite it to avoid symbols in the names of non-terminals, and to instead wrap terminals in backquotes. Also rename "smallntp" to "small_no_tuple" to make it self-describing.
2 parents 70e8f9d + 79df44b commit c668eb0

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/doc/style-guide/src/expressions.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,9 @@ not put the `if` clause on a newline. E.g.,
753753
}
754754
```
755755

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

760760
```rust
761761
foo | bar | baz
@@ -764,17 +764,18 @@ possible. Again break before a `|`:
764764
}
765765
```
766766

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

769770
```
770-
[small, ntp]:
771-
- single token
772-
- `&[single-line, ntp]`
771+
small:
772+
- small_no_tuple
773+
- unary tuple constructor: `(` small_no_tuple `,` `)`
774+
- `&` small
773775
774-
[small]:
775-
- `[small, ntp]`
776-
- unary tuple constructor `([small, ntp])`
777-
- `&[small]`
776+
small_no_tuple:
777+
- single token
778+
- `&` small_no_tuple
778779
```
779780

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

0 commit comments

Comments
 (0)