From 3ad356a17a390119528afdd088817d77232c2647 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 2 Oct 2024 13:52:02 -0700 Subject: [PATCH] 2024: Update `expr` macro fragment specifier --- src/macros-by-example.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/macros-by-example.md b/src/macros-by-example.md index aa04467d1..90c21baab 100644 --- a/src/macros-by-example.md +++ b/src/macros-by-example.md @@ -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] @@ -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. @@ -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