diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 91617f2df9c..1c76c31e1a7 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -888,8 +888,10 @@ fn resolve_macro_invocation( /// Some parent node that is close enough to the given macro call. fn lint_node_id(&mut self, expn_id: ExpnId) -> NodeId; + // Resolver interfaces for specific built-in macros. + /// Does `#[derive(...)]` attribute with the given `ExpnId` have built-in `Copy` inside it? fn has_derive_copy(&self, expn_id: ExpnId) -> bool; - fn add_derive_copy(&mut self, expn_id: ExpnId); + /// Path resolution logic for `#[cfg_accessible(path)]`. fn cfg_accessible(&mut self, expn_id: ExpnId, path: &ast::Path) -> Result; } diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index d4a83b80990..f4b66b35420 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1797,7 +1797,4 @@ pub fn default(crate_name: String) -> ExpansionConfig<'static> { fn proc_macro_hygiene(&self) -> bool { self.features.map_or(false, |features| features.proc_macro_hygiene) } - fn custom_inner_attributes(&self) -> bool { - self.features.map_or(false, |features| features.custom_inner_attributes) - } } 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 @@ fn parse_meta_item_inner(&mut self) -> PResult<'a, ast::NestedMetaItem> { } 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) + }) }) } diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index b1ea2d73786..1ee96f81e4f 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -286,7 +286,7 @@ fn resolve_macro_invocation( ext.helper_attrs.iter().map(|name| Ident::new(*name, span)), ); if ext.is_derive_copy { - self.add_derive_copy(invoc_id); + self.containers_deriving_copy.insert(invoc_id); } ext } @@ -351,10 +351,6 @@ fn has_derive_copy(&self, expn_id: ExpnId) -> bool { self.containers_deriving_copy.contains(&expn_id) } - fn add_derive_copy(&mut self, expn_id: ExpnId) { - self.containers_deriving_copy.insert(expn_id); - } - // The function that implements the resolution logic of `#[cfg_accessible(path)]`. // Returns true if the path can certainly be resolved in one of three namespaces, // returns false if the path certainly cannot be resolved in any of the three namespaces.