-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Non-terminals, e.g. expr, have diverged between parser and macro matcher #86730
Copy link
Copy link
Open
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-maybe-future-editionSomething we may consider for a future edition.Something we may consider for a future edition.A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTF-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)Inline constants (aka: const blocks, const expressions, anonymous constants)F-let_chains`#![feature(let_chains)]``#![feature(let_chains)]`T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-maybe-future-editionSomething we may consider for a future edition.Something we may consider for a future edition.A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTF-inline_constInline constants (aka: const blocks, const expressions, anonymous constants)Inline constants (aka: const blocks, const expressions, anonymous constants)F-let_chains`#![feature(let_chains)]``#![feature(let_chains)]`T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Needs help: Impl
Spawned off of PR #84364, based on discussion from lang team meeting (minutes, youtube).
The meaning of the non-terminal "expr" according to the rustc parser has changed (or would like to change) from its meaning according to the current rustc macro matcher.
Concretely:
inline_constfeature has already added a production roughly of the formEXPR ::= const { EXPR }let_chainsfeature may want (in the future) to add a production roughly of the formCOND_EXPR ::= let PAT = EXPR, whereCOND_EXPRcan occur as a sub-expression in the condition that drives anifexpression orwhilestatement.In both cases, for backwards compatibility, the
exprfragment specifier does not accept these new productions. Examples of the kinds of problems this causes follow:In other words, today you simply cannot write a macro fragment specifier denoting expressions that will match
const { EXPR }orlet PAT = EXPR, other than something like$e:tt, which would also match arbitrary token-trees, which won't catch errors as effectively as a more precise fragment specifier.So, the main question this raises is: How should we resolve this divergence between the parser and macro-rules matcher?
expr2024) that covers the new forms and call it a day.exprfragment specifier to cover the new forms. (This would probably need to be coupled with an addition of a new fragment specifier that would capture the old semantics.)exprmatches now that it did not before.