-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Allow #[attr] if to be passed to proc macros #68618
Copy link
Copy link
Closed
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
The following code:
produces this error:
Proc macros like
pin-projectcurrently use a trick to work around attributes on expressions being unstable: The entire function is annotated with a 'wrapper' attribute, which goes through and manually parses expression attributes. For example:In the example above, the
#[my_attr] let a = 25;will be processed by the outer#[my_attr] fn foo()implementation, which will strip away the expression-based#[my_attr]before emitting the finalTokenStream.Unfortunately, the current 'attributes are not yet allowed on
ifexpressions' check is done during parsing:rust/src/librustc_parse/parser/expr.rs
Line 679 in ac2f3fa
While the proc-macro itself can parse the attribute on the
if letwithout any errors, compilation will still fail due to the parsing error that was emitted before any proc-macros were run.It would be extremely useful if this check were to be moved until after parsing, so that proc macros had a chance to remove attributes from
ifexpressions.