Skip to content

Commit

Permalink
Add expr_2021 macro fragment specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 2, 2024
1 parent 420e2bc commit e4ba8b0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/macros-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ r[macro.decl.syntax]
> &nbsp;&nbsp; | `$` `(` _MacroMatch_<sup>+</sup> `)` _MacroRepSep_<sup>?</sup> _MacroRepOp_
>
> _MacroFragSpec_ :\
> &nbsp;&nbsp; &nbsp;&nbsp; `block` | `expr` | `ident` | `item` | `lifetime` | `literal`\
> &nbsp;&nbsp; &nbsp;&nbsp; `block` | `expr` | `expr_2021` | `ident` | `item` | `lifetime` | `literal`\
> &nbsp;&nbsp; | `meta` | `pat` | `pat_param` | `path` | `stmt` | `tt` | `ty` | `vis`
>
> _MacroRepSep_ :\
Expand Down Expand Up @@ -143,7 +143,8 @@ Valid fragment specifiers are:
statements that require semicolons)
* `pat_param`: a [_PatternNoTopAlt_]
* `pat`: at least any [_PatternNoTopAlt_], and possibly more depending on edition
* `expr`: an [_Expression_]
* `expr`: an [_Expression_] except [_UnderscoreExpression_] and [_ConstBlockExpression_] (see [macro.decl.meta.expr-underscore])
* `expr_2021`: same as `expr` (see [macro.decl.meta.edition2021])
* `ty`: a [_Type_]
* `ident`: an [IDENTIFIER_OR_KEYWORD] or [RAW_IDENTIFIER]
* `path`: a [_TypePath_] style path
Expand Down Expand Up @@ -175,6 +176,8 @@ r[macro.decl.meta.edition2021]
> Before the 2021 edition, they match exactly the same fragments as `pat_param` (that is, they accept [_PatternNoTopAlt_]).
>
> The relevant edition is the one in effect for the `macro_rules!` definition.
>
> The `expr_2021` fragment specifier exists to maintain backwards compatibility with editions before 2024.
## Repetitions

Expand Down Expand Up @@ -572,6 +575,7 @@ For more detail, see the [formal specification].
[Repetitions]: #repetitions
[_Attr_]: attributes.md
[_BlockExpression_]: expressions/block-expr.md
[_ConstBlockExpression_]: expressions/block-expr.md#const-blocks
[_DelimTokenTree_]: macros.md
[_Expression_]: expressions.md
[_Item_]: items.md
Expand Down

0 comments on commit e4ba8b0

Please sign in to comment.