Skip to content

Commit

Permalink
2024: Update expr macro fragment specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Nov 4, 2024
1 parent da0f6da commit 3ad356a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/macros-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ r[macro.decl.meta.specifier]
Valid fragment specifiers are:

* `block`: a [_BlockExpression_]
* `expr`: an [_Expression_] except [_UnderscoreExpression_] and [_ConstBlockExpression_] (see [macro.decl.meta.expr-underscore])
* `expr_2021`: same as `expr` (see [macro.decl.meta.edition2021])
* `expr`: an [_Expression_]
* `expr_2021`: an [_Expression_] except [_UnderscoreExpression_] and [_ConstBlockExpression_] (see [macro.decl.meta.edition2024])
* `ident`: an [IDENTIFIER_OR_KEYWORD] or [RAW_IDENTIFIER]
* `item`: an [_Item_]
* `lifetime`: a [LIFETIME_TOKEN]
Expand All @@ -162,19 +162,15 @@ r[macro.decl.meta.dollar-crate]
The keyword metavariable `$crate` can be used to refer to the current crate; see [Hygiene] below. Metavariables can be
transcribed more than once or not at all.

r[macro.decl.meta.expr-underscore]
For reasons of backwards compatibility, though `_` [is also an
expression][_UnderscoreExpression_], a standalone underscore is not matched by
the `expr` fragment specifier. However, `_` is matched by the `expr` fragment
specifier when it appears as a subexpression.
For the same reason, a standalone [const block] is not matched but it is matched when appearing as a subexpression.

r[macro.decl.meta.edition2021]
> **Edition differences**: Starting with the 2021 edition, `pat` fragment-specifiers match top-level or-patterns (that is, they accept [_Pattern_]).
>
> 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.
r[macro.decl.meta.edition2024]
> **Edition differences**: Before the 2024 edition, `expr` fragment specifiers do not match [_UnderscoreExpression_] or [_ConstBlockExpression_] at the top level. They are allowed within subexpressions.
>
> The `expr_2021` fragment specifier exists to maintain backwards compatibility with editions before 2024.
Expand Down Expand Up @@ -600,7 +596,6 @@ expansions, taking separators into account. This means:
For more detail, see the [formal specification].

[block labels]: expressions/loop-expr.md#labelled-block-expressions
[const block]: expressions/block-expr.md#const-blocks
[Hygiene]: #hygiene
[IDENTIFIER]: identifiers.md
[IDENTIFIER_OR_KEYWORD]: identifiers.md
Expand Down

0 comments on commit 3ad356a

Please sign in to comment.