Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Syntactically permit attributes on 'if' expressions
Fixes rust-lang#68618 Previously, attributes on 'if' expressions (e.g. `#[attr] if true {}`) were disallowed during parsing. This made it impossible for macros to perform any custom handling of such attributes (e.g. stripping them away), since a compilation error would be emitted before they ever had a chance to run. This PR permits attributes on 'if' expressions ('if-attrs' from here on) syntactically, i.e. during parsing. We instead deny if-attrs during AST validation, which occurs after all macro expansions have run. This is a conservative change which allows more code to be processed by macros. It does not commit us to *semantically* accepting if-attrs. For example, the following code is not allowed even with this PR: ```rust fn builtin_attr() { #[allow(warnings)] if true {} } fn custom_attr() { #[my_proc_macro_attr] if true {} } ``` However, the following code *is* accepted ```rust #[cfg(FALSE)] fn foo() { #[allow(warnings)] if true {} #[my_custom_attr] if true {} } #[my_custom_attr] fn use_within_body() { #[allow(warnings)] if true {} #[my_custom_attr] if true {} } ```
- Loading branch information