Skip to content

Commit 245b833

Browse files
committed
address review comments
1 parent 4c75c0b commit 245b833

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

src/expressions/closure-expr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Attributes on closure parameters follow the same rules and restrictions as
8080
[_Expression_]: ../expressions.md
8181
[_BlockExpression_]: block-expr.md
8282
[_TypeNoBounds_]: ../types.md#type-expressions
83-
[_Pattern_]: ../patterns.md
83+
[_PatternNoTopAlt_]: ../patterns.md
8484
[_Type_]: ../types.md#type-expressions
8585
[`let` binding]: ../statements.md#let-statements
8686
[_OuterAttribute_]: ../attributes.md

src/items/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ fn foo_oof(#[some_inert_attribute] arg: u8) {
378378
[_BlockExpression_]: ../expressions/block-expr.md
379379
[_GenericParams_]: generics.md
380380
[_Lifetime_]: ../trait-bounds.md
381-
[_Pattern_]: ../patterns.md
381+
[_PatternNoTopAlt_]: ../patterns.md
382382
[_Type_]: ../types.md#type-expressions
383383
[_WhereClause_]: generics.md#where-clauses
384384
[_OuterAttribute_]: ../attributes.md

src/macros-by-example.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
>
2929
> _MacroFragSpec_ :\
3030
>       `block` | `expr` | `ident` | `item` | `lifetime` | `literal`\
31-
>    | `meta` | `pat` | `path` | `stmt` | `tt` | `ty` | `vis`
31+
>    | `meta` | `pat` | `pat2015` | `pat2021` | `path` | `stmt` | `tt` | `ty` | `vis`
3232
>
3333
> _MacroRepSep_ :\
3434
> &nbsp;&nbsp; [_Token_]<sub>_except delimiters and repetition operators_</sub>
@@ -122,7 +122,9 @@ fragment specifiers are:
122122
* `block`: a [_BlockExpression_]
123123
* `stmt`: a [_Statement_] without the trailing semicolon (except for item
124124
statements that require semicolons)
125-
* `pat`: a [_Pattern_]
125+
* `pat2015`: a [_PatternNoTopAlt_]
126+
* `pat2021`: a [_Pattern_]
127+
* `pat`: equivalent to either `pat2015` or `pat2021`, depending on edition (see note below).
126128
* `expr`: an [_Expression_]
127129
* `ty`: a [_Type_]
128130
* `ident`: an [IDENTIFIER_OR_KEYWORD]
@@ -133,6 +135,11 @@ fragment specifiers are:
133135
* `vis`: a possibly empty [_Visibility_] qualifier
134136
* `literal`: matches `-`<sup>?</sup>[_LiteralExpression_]
135137

138+
> **Edition Differences**: In Editions 2015 and 2018, `pat` fragment-specifiers
139+
> do not allow top-level or-patterns (i.e. they accept [_PatternNoTopAlt_]). In
140+
> Edition 2021, this was changed so that top-level or-patterns are accepted by
141+
> `pat` (i.e. [_Pattern_]).
142+
136143
In the transcriber, metavariables are referred to simply by `$`_name_, since
137144
the fragment kind is specified in the matcher. Metavariables are replaced with
138145
the syntax element that matched them. The keyword metavariable `$crate` can be
@@ -489,6 +496,7 @@ For more detail, see the [formal specification].
489496
[_LiteralExpression_]: expressions/literal-expr.md
490497
[_MetaListIdents_]: attributes.md#meta-item-attribute-syntax
491498
[_Pattern_]: patterns.md
499+
[_PatternNoTopAlt_]: patterns.md
492500
[_Statement_]: statements.md
493501
[_TokenTree_]: macros.md#macro-invocation
494502
[_Token_]: tokens.md

src/patterns.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
> **<sup>Syntax</sup>**\
44
> _Pattern_ :\
5-
> &nbsp;&nbsp; &nbsp;&nbsp; `|`<sup>?</sup> _PatternNoTopAlt_ `|` _PatternNoTopAlt_
6-
> &nbsp;&nbsp; | _PatternNoTopAlt_
5+
> &nbsp;&nbsp; &nbsp;&nbsp; `|`<sup>?</sup> _PatternNoTopAlt_ ( `|` _PatternNoTopAlt_ )<sup>\*</sup>
76
>
87
> _PatternNoTopAlt_ :\
98
> &nbsp;&nbsp; &nbsp;&nbsp; _PatternWithoutRange_\
10-
> &nbsp;&nbsp; | [_RangePattern_]
9+
> &nbsp;&nbsp; | [_RangePattern_]\
1110
> &nbsp;&nbsp; | `(` _Pattern_ `)`
1211
>
1312
> _PatternWithoutRange_ :\
@@ -763,12 +762,11 @@ refer to refutable constants or enum variants for enums with multiple variants.
763762

764763
## Or-patterns
765764

766-
_Or-patterns_ are patterns that match on either of two sub-patterns (e.g. `A |
767-
B`). They can nest arbitrarily. Syntactically, or-patterns are allowed in any
768-
of the places where other patterns are allowed (represented by the _Pattern_
769-
production), with the exceptions of function and closure arguments (represented
770-
by the _PatternNoTopAlt_ production). Additionally, the macro `:pat` matchers
771-
only match or-patterns in the 2021+ editions.
765+
_Or-patterns_ are patterns that match on one of two or more sub-patterns (e.g.
766+
`A | B | C`). They can nest arbitrarily. Syntactically, or-patterns are allowed
767+
in any of the places where other patterns are allowed (represented by the
768+
_Pattern_ production), with the exceptions of `let`-bindings and function and
769+
closure arguments (represented by the _PatternNoTopAlt_ production).
772770

773771
### Static semantics
774772

@@ -780,8 +778,6 @@ only match or-patterns in the 2021+ editions.
780778
+ the type of any two bindings with the same name in `p` and `q` do not unify
781779
with respect to types or binding modes.
782780

783-
[type coercions]: https://doc.rust-lang.org/reference/type-coercions.html
784-
785781
Unification of types is in all instances aforementioned exact and
786782
implicit [type coercions] do not apply.
787783

@@ -838,3 +834,4 @@ only match or-patterns in the 2021+ editions.
838834
[structs]: items/structs.md
839835
[tuples]: types/tuple.md
840836
[scrutinee]: glossary.md#scrutinee
837+
[type coercions]: type-coercions.md

src/statements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ statement are [`cfg`], and [the lint check attributes].
133133
[_LetStatement_]: #let-statements
134134
[_MacroInvocationSemi_]: macros.md#macro-invocation
135135
[_OuterAttribute_]: attributes.md
136-
[_Pattern_]: patterns.md
136+
[_PatternNoTopAlt_]: patterns.md
137137
[_Type_]: types.md

0 commit comments

Comments
 (0)