Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024: Update expr macro fragment specifier #1639

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2024: Update expr macro fragment specifier
  • Loading branch information
ehuss committed Nov 4, 2024
commit 3ad356a17a390119528afdd088817d77232c2647
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