From cde67f65573f54fa59aa954cea9b4e3504a7a8dd Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 5 Jul 2023 14:40:07 -0700 Subject: [PATCH 1/2] 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. --- src/doc/style-guide/src/expressions.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/doc/style-guide/src/expressions.md b/src/doc/style-guide/src/expressions.md index f5e37b6c46f69..a2994baaddc8d 100644 --- a/src/doc/style-guide/src/expressions.md +++ b/src/doc/style-guide/src/expressions.md @@ -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 @@ -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: + - smallntp + - unary tuple constructor: `(` smallntp `,` `)` + - `&` small -[small]: - - `[small, ntp]` - - unary tuple constructor `([small, ntp])` - - `&[small]` +smallntp: + - single token + - `&` smallntp ``` E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not. From 79df44ba78a10f5ca4cae70d81aa98bfb402e05a Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 5 Jul 2023 14:49:59 -0700 Subject: [PATCH 2/2] style-guide: Rename "smallntp" non-terminal to "small_no_tuple" for clarity The meaning of "smallntp" was not immediately obvious at a glance. Rename it to the self-describing "small_no_tuple" --- src/doc/style-guide/src/expressions.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/style-guide/src/expressions.md b/src/doc/style-guide/src/expressions.md index a2994baaddc8d..cb934990e9829 100644 --- a/src/doc/style-guide/src/expressions.md +++ b/src/doc/style-guide/src/expressions.md @@ -768,13 +768,13 @@ matches "small" in the following grammar: ``` small: - - smallntp - - unary tuple constructor: `(` smallntp `,` `)` + - small_no_tuple + - unary tuple constructor: `(` small_no_tuple `,` `)` - `&` small -smallntp: +small_no_tuple: - single token - - `&` smallntp + - `&` small_no_tuple ``` E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.