Skip to content

Commit

Permalink
resolve/expand: Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Nov 19, 2020
1 parent 68f94e9 commit dfb690e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,10 @@ pub trait ResolverExpand {
/// 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<bool, Indeterminate>;
}

Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,4 @@ impl<'feat> ExpansionConfig<'feat> {
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)
}
}
13 changes: 6 additions & 7 deletions compiler/rustc_parse/src/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
}
6 changes: 1 addition & 5 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
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
}
Expand Down Expand Up @@ -351,10 +351,6 @@ impl<'a> ResolverExpand for Resolver<'a> {
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.
Expand Down

0 comments on commit dfb690e

Please sign in to comment.