@@ -123,7 +123,7 @@ fragment specifiers are:
123
123
* ` stmt ` : a [ _ Statement_ ] without the trailing semicolon (except for item
124
124
statements that require semicolons)
125
125
* ` pat_param ` : a [ _ PatternNoTopAlt_ ]
126
- * ` pat ` : equivalent to ` pat_param `
126
+ * ` pat ` : at least any [ _ PatternNoTopAlt _ ] , and possibly more depending on edition
127
127
* ` expr ` : an [ _ Expression_ ]
128
128
* ` ty ` : a [ _ Type_ ]
129
129
* ` ident ` : an [ IDENTIFIER_OR_KEYWORD] or [ RAW_IDENTIFIER]
@@ -140,6 +140,12 @@ the syntax element that matched them. The keyword metavariable `$crate` can be
140
140
used to refer to the current crate; see [ Hygiene] below. Metavariables can be
141
141
transcribed more than once or not at all.
142
142
143
+ > ** Edition Differences** : Starting with the 2021 edition, ` pat ` fragment-specifiers match top-level or-patterns (that is, they accept [ _ Pattern_ ] ).
144
+ >
145
+ > Before the 2021 edition, they match exactly the same fragments as ` pat_param ` (that is, they accept [ _ PatternNoTopAlt_ ] ).
146
+ >
147
+ > The relevant edition is the one in effect for the ` macro_rules! ` definition.
148
+
143
149
## Repetitions
144
150
145
151
In both the matcher and transcriber, repetitions are indicated by placing the
@@ -451,7 +457,8 @@ Matchers like `$i:expr,` or `$i:expr;` would be legal, however, because `,` and
451
457
` ; ` are legal expression separators. The specific rules are:
452
458
453
459
* ` expr ` and ` stmt ` may only be followed by one of: ` => ` , ` , ` , or ` ; ` .
454
- * ` pat ` and ` pat_param ` may only be followed by one of: ` => ` , ` , ` , ` = ` , ` | ` , ` if ` , or ` in ` .
460
+ * ` pat_param ` may only be followed by one of: ` => ` , ` , ` , ` = ` , ` | ` , ` if ` , or ` in ` .
461
+ * ` pat ` may only be followed by one of: ` => ` , ` , ` , ` = ` , ` if ` , or ` in ` .
455
462
* ` path ` and ` ty ` may only be followed by one of: ` => ` , ` , ` , ` = ` , ` | ` , ` ; ` ,
456
463
` : ` , ` > ` , ` >> ` , ` [ ` , ` { ` , ` as ` , ` where ` , or a macro variable of ` block `
457
464
fragment specifier.
@@ -460,6 +467,8 @@ Matchers like `$i:expr,` or `$i:expr;` would be legal, however, because `,` and
460
467
` ident ` , ` ty ` , or ` path ` fragment specifier.
461
468
* All other fragment specifiers have no restrictions.
462
469
470
+ > ** Edition Differences** : Before the 2021 edition, ` pat ` may also be followed by ` | ` .
471
+
463
472
When repetitions are involved, then the rules apply to every possible number of
464
473
expansions, taking separators into account. This means:
465
474
@@ -490,6 +499,7 @@ For more detail, see the [formal specification].
490
499
[ _Item_ ] : items.md
491
500
[ _LiteralExpression_ ] : expressions/literal-expr.md
492
501
[ _MetaListIdents_ ] : attributes.md#meta-item-attribute-syntax
502
+ [ _Pattern_ ] : patterns.md
493
503
[ _PatternNoTopAlt_ ] : patterns.md
494
504
[ _Statement_ ] : statements.md
495
505
[ _TokenTree_ ] : macros.md#macro-invocation
0 commit comments