Skip to content

Commit 5534e9c

Browse files
committed
2024: Add macro_rules expr and expr_2021
1 parent 135bdee commit 5534e9c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/macros-by-example.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
> &nbsp;&nbsp; | `$` `(` _MacroMatch_<sup>+</sup> `)` _MacroRepSep_<sup>?</sup> _MacroRepOp_
2828
>
2929
> _MacroFragSpec_ :\
30-
> &nbsp;&nbsp; &nbsp;&nbsp; `block` | `expr` | `ident` | `item` | `lifetime` | `literal`\
30+
> &nbsp;&nbsp; &nbsp;&nbsp; `block` | `expr` | `expr_2021` | `ident` | `item` | `lifetime` | `literal`\
3131
> &nbsp;&nbsp; | `meta` | `pat` | `pat_param` | `path` | `stmt` | `tt` | `ty` | `vis`
3232
>
3333
> _MacroRepSep_ :\
@@ -127,6 +127,7 @@ fragment specifiers are:
127127
* `pat_param`: a [_PatternNoTopAlt_]
128128
* `pat`: at least any [_PatternNoTopAlt_], and possibly more depending on edition
129129
* `expr`: an [_Expression_]
130+
* `expr_2021` an [_Expression_] except [_UnderscoreExpression_] and [_ConstBlockExpression_]
130131
* `ty`: a [_Type_]
131132
* `ident`: an [IDENTIFIER_OR_KEYWORD] or [RAW_IDENTIFIER]
132133
* `path`: a [_TypePath_] style path
@@ -142,16 +143,13 @@ the syntax element that matched them. The keyword metavariable `$crate` can be
142143
used to refer to the current crate; see [Hygiene] below. Metavariables can be
143144
transcribed more than once or not at all.
144145

145-
For reasons of backwards compatibility, though `_` [is also an
146-
expression][_UnderscoreExpression_], a standalone underscore is not matched by
147-
the `expr` fragment specifier. However, `_` is matched by the `expr` fragment
148-
specifier when it appears as a subexpression.
149-
For the same reason, a standalone [const block] is not matched but it is matched when appearing as a subexpression.
150-
151146
> **Edition Differences**: Starting with the 2021 edition, `pat` fragment-specifiers match top-level or-patterns (that is, they accept [_Pattern_]).
152147
>
153148
> Before the 2021 edition, they match exactly the same fragments as `pat_param` (that is, they accept [_PatternNoTopAlt_]).
154149
>
150+
> Before the 2024 edition, `expr` fragment specifiers do not match [_UnderscoreExpression_] or [_ConstBlockExpression_] at the top level. They are allowed within subexpressions.
151+
> The `expr_2021` fragment specifier exists as a way to maintain backwards compatibility if needed.
152+
>
155153
> The relevant edition is the one in effect for the `macro_rules!` definition.
156154
157155
## Repetitions
@@ -493,7 +491,7 @@ expansions, taking separators into account. This means:
493491

494492
For more detail, see the [formal specification].
495493

496-
[const block]: expressions/block-expr.md#const-blocks
494+
[_ConstBlockExpression_]: expressions/block-expr.md#const-blocks
497495
[Hygiene]: #hygiene
498496
[IDENTIFIER]: identifiers.md
499497
[IDENTIFIER_OR_KEYWORD]: identifiers.md

0 commit comments

Comments
 (0)