Skip to content

Commit efc2cf3

Browse files
committed
Document the 2021 edition changes to macros-by-example pat metavariables
1 parent 434eb96 commit efc2cf3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/macros-by-example.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fragment specifiers are:
123123
* `stmt`: a [_Statement_] without the trailing semicolon (except for item
124124
statements that require semicolons)
125125
* `pat_param`: a [_PatternNoTopAlt_]
126-
* `pat`: equivalent to `pat_param`
126+
* `pat`: at least any [_PatternNoTopAlt_], and possibly more depending on edition
127127
* `expr`: an [_Expression_]
128128
* `ty`: a [_Type_]
129129
* `ident`: an [IDENTIFIER_OR_KEYWORD] or [RAW_IDENTIFIER]
@@ -140,6 +140,10 @@ the syntax element that matched them. The keyword metavariable `$crate` can be
140140
used to refer to the current crate; see [Hygiene] below. Metavariables can be
141141
transcribed more than once or not at all.
142142

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+
143147
## Repetitions
144148

145149
In both the matcher and transcriber, repetitions are indicated by placing the
@@ -451,7 +455,8 @@ Matchers like `$i:expr,` or `$i:expr;` would be legal, however, because `,` and
451455
`;` are legal expression separators. The specific rules are:
452456

453457
* `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`.
458+
* `pat_param` may only be followed by one of: `=>`, `,`, `=`, `|`, `if`, or `in`.
459+
* `pat` may only be followed by one of: `=>`, `,`, `=`, `if`, or `in`.
455460
* `path` and `ty` may only be followed by one of: `=>`, `,`, `=`, `|`, `;`,
456461
`:`, `>`, `>>`, `[`, `{`, `as`, `where`, or a macro variable of `block`
457462
fragment specifier.
@@ -460,6 +465,8 @@ Matchers like `$i:expr,` or `$i:expr;` would be legal, however, because `,` and
460465
`ident`, `ty`, or `path` fragment specifier.
461466
* All other fragment specifiers have no restrictions.
462467

468+
> **Edition Differences**: Before the 2021 edition, `pat` may also be followed by `|`.
469+
463470
When repetitions are involved, then the rules apply to every possible number of
464471
expansions, taking separators into account. This means:
465472

@@ -490,6 +497,7 @@ For more detail, see the [formal specification].
490497
[_Item_]: items.md
491498
[_LiteralExpression_]: expressions/literal-expr.md
492499
[_MetaListIdents_]: attributes.md#meta-item-attribute-syntax
500+
[_Pattern_]: patterns.md
493501
[_PatternNoTopAlt_]: patterns.md
494502
[_Statement_]: statements.md
495503
[_TokenTree_]: macros.md#macro-invocation

0 commit comments

Comments
 (0)