From 53de24bbd1b87cf37457568f67c2b483f196de9b Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Wed, 19 Oct 2016 06:51:40 +0000 Subject: [PATCH] Refactor away fields `MacroDef::{use_locally, export}`. --- src/librustc/hir/lowering.rs | 2 -- src/librustc/hir/mod.rs | 2 -- .../calculate_svh/svh_visitor.rs | 12 ++++----- src/librustc_metadata/creader.rs | 3 --- src/librustc_resolve/macros.rs | 26 +++++++++---------- src/libsyntax/ast.rs | 2 -- src/libsyntax/ext/base.rs | 4 +-- src/libsyntax/ext/tt/macro_rules.rs | 5 ++-- 8 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 80340f9a9255..562156e70bd9 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -716,8 +716,6 @@ impl<'a> LoweringContext<'a> { id: m.id, span: m.span, imported_from: m.imported_from.map(|x| x.name), - export: m.export, - use_locally: m.use_locally, allow_internal_unstable: m.allow_internal_unstable, body: m.body.clone().into(), } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6e81c3e700ed..1de4355ccdfd 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -458,8 +458,6 @@ pub struct MacroDef { pub id: NodeId, pub span: Span, pub imported_from: Option, - pub export: bool, - pub use_locally: bool, pub allow_internal_unstable: bool, pub body: HirVec, } diff --git a/src/librustc_incremental/calculate_svh/svh_visitor.rs b/src/librustc_incremental/calculate_svh/svh_visitor.rs index 584e5598b9f9..51c894e1b78f 100644 --- a/src/librustc_incremental/calculate_svh/svh_visitor.rs +++ b/src/librustc_incremental/calculate_svh/svh_visitor.rs @@ -675,13 +675,11 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has fn visit_macro_def(&mut self, macro_def: &'tcx MacroDef) { debug!("visit_macro_def: st={:?}", self.st); - if macro_def.export { - SawMacroDef.hash(self.st); - hash_attrs!(self, ¯o_def.attrs); - visit::walk_macro_def(self, macro_def) - // FIXME(mw): We should hash the body of the macro too but we don't - // have a stable way of doing so yet. - } + SawMacroDef.hash(self.st); + hash_attrs!(self, ¯o_def.attrs); + visit::walk_macro_def(self, macro_def) + // FIXME(mw): We should hash the body of the macro too but we don't + // have a stable way of doing so yet. } } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index ad2a7afbc8b6..33ed423520df 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -594,9 +594,6 @@ impl<'a> CrateLoader<'a> { id: ast::DUMMY_NODE_ID, span: local_span, imported_from: Some(item.ident), - // overridden in plugin/load.rs - export: false, - use_locally: false, allow_internal_unstable: attr::contains_name(&def.attrs, "allow_internal_unstable"), attrs: def.attrs, body: body, diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 0f42b4520c9b..72e5823598ea 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -114,22 +114,22 @@ impl<'a> base::Resolver for Resolver<'a> { invocation.expansion.set(visitor.legacy_scope); } - fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef) { + fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef, export: bool) { if &def.ident.name.as_str() == "macro_rules" { self.session.span_err(def.span, "user-defined macros may not be named `macro_rules`"); } - if def.use_locally { - let invocation = self.invocations[&scope]; - let binding = self.arenas.alloc_legacy_binding(LegacyBinding { - parent: invocation.legacy_scope.get(), - name: def.ident.name, - ext: Rc::new(macro_rules::compile(&self.session.parse_sess, &def)), - span: def.span, - }); - invocation.legacy_scope.set(LegacyScope::Binding(binding)); - self.macro_names.insert(def.ident.name); - } - if def.export { + + let invocation = self.invocations[&scope]; + let binding = self.arenas.alloc_legacy_binding(LegacyBinding { + parent: invocation.legacy_scope.get(), + name: def.ident.name, + ext: Rc::new(macro_rules::compile(&self.session.parse_sess, &def)), + span: def.span, + }); + invocation.legacy_scope.set(LegacyScope::Binding(binding)); + self.macro_names.insert(def.ident.name); + + if export { def.id = self.next_node_id(); self.exported_macros.push(def); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 30fc4c3dd804..ae036e66c690 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -2012,8 +2012,6 @@ pub struct MacroDef { pub id: NodeId, pub span: Span, pub imported_from: Option, - pub export: bool, - pub use_locally: bool, pub allow_internal_unstable: bool, pub body: Vec, } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index f3272960e831..c404c6d1162f 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -519,7 +519,7 @@ pub trait Resolver { fn get_module_scope(&mut self, id: ast::NodeId) -> Mark; fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion); - fn add_macro(&mut self, scope: Mark, def: ast::MacroDef); + fn add_macro(&mut self, scope: Mark, def: ast::MacroDef, export: bool); fn add_ext(&mut self, ident: ast::Ident, ext: Rc); fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec); @@ -541,7 +541,7 @@ impl Resolver for DummyResolver { fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() } fn visit_expansion(&mut self, _invoc: Mark, _expansion: &Expansion) {} - fn add_macro(&mut self, _scope: Mark, _def: ast::MacroDef) {} + fn add_macro(&mut self, _scope: Mark, _def: ast::MacroDef, _export: bool) {} fn add_ext(&mut self, _ident: ast::Ident, _ext: Rc) {} fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec) {} diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 61911e0d3b3d..ceca698f479a 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -157,14 +157,13 @@ impl IdentMacroExpander for MacroRulesExpander { tts: Vec, attrs: Vec) -> Box { + let export = attr::contains_name(&attrs, "macro_export"); let def = ast::MacroDef { ident: ident, id: ast::DUMMY_NODE_ID, span: span, imported_from: None, - use_locally: true, body: tts, - export: attr::contains_name(&attrs, "macro_export"), allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"), attrs: attrs, }; @@ -176,7 +175,7 @@ impl IdentMacroExpander for MacroRulesExpander { MacEager::items(placeholders::macro_scope_placeholder().make_items()) }; - cx.resolver.add_macro(cx.current_expansion.mark, def); + cx.resolver.add_macro(cx.current_expansion.mark, def, export); result } }