about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-11-19 23:58:42 +0100
committerGitHub <noreply@github.com>2020-11-19 23:58:42 +0100
commit8216b359e542d6d842bc3ed3fba3c67de5ad60fa (patch)
tree2a600321f93e27da52723d7250b1c371e17b1150 /compiler/rustc_parse/src/parser
parentd5ee4edee10e1d39e205341eeace4f9ba26d389a (diff)
parentd575aa4d580676eac7c02092ca94e5cfa421b288 (diff)
downloadrust-8216b359e542d6d842bc3ed3fba3c67de5ad60fa.tar.gz
rust-8216b359e542d6d842bc3ed3fba3c67de5ad60fa.zip
Rollup merge of #79185 - petrochenkov:derattr2, r=Aaron1011
expand/resolve: Pre-requisites to "Turn `#[derive]` into a regular macro attribute"

Miscellaneous refactorings and error reporting changes extracted from https://github.com/rust-lang/rust/pull/79078.

Unlike https://github.com/rust-lang/rust/pull/79078 this PR doesn't make any observable changes to the language or library.
r? ```@Aaron1011```
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/attr.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs
index 3738fbaeac8..41985757b57 100644
--- a/compiler/rustc_parse/src/parser/attr.rs
+++ b/compiler/rustc_parse/src/parser/attr.rs
@@ -312,14 +312,13 @@ impl<'a> Parser<'a> {
 }
 
 pub fn maybe_needs_tokens(attrs: &[ast::Attribute]) -> bool {
+    // One of the attributes may either itself be a macro, or apply derive macros (`derive`),
+    // or expand to macro attributes (`cfg_attr`).
     attrs.iter().any(|attr| {
-        if let Some(ident) = attr.ident() {
+        attr.ident().map_or(true, |ident| {
             ident.name == sym::derive
-            // This might apply a custom attribute/derive
-            || ident.name == sym::cfg_attr
-            || !rustc_feature::is_builtin_attr_name(ident.name)
-        } else {
-            true
-        }
+                || ident.name == sym::cfg_attr
+                || !rustc_feature::is_builtin_attr_name(ident.name)
+        })
     })
 }