Refactor away fields MacroDef::{use_locally, export}.
This commit is contained in:
@@ -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(),
|
||||
}
|
||||
|
||||
@@ -458,8 +458,6 @@ pub struct MacroDef {
|
||||
pub id: NodeId,
|
||||
pub span: Span,
|
||||
pub imported_from: Option<Name>,
|
||||
pub export: bool,
|
||||
pub use_locally: bool,
|
||||
pub allow_internal_unstable: bool,
|
||||
pub body: HirVec<TokenTree>,
|
||||
}
|
||||
|
||||
@@ -675,14 +675,12 @@ 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -114,11 +114,11 @@ 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(),
|
||||
@@ -128,8 +128,8 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||
});
|
||||
invocation.legacy_scope.set(LegacyScope::Binding(binding));
|
||||
self.macro_names.insert(def.ident.name);
|
||||
}
|
||||
if def.export {
|
||||
|
||||
if export {
|
||||
def.id = self.next_node_id();
|
||||
self.exported_macros.push(def);
|
||||
}
|
||||
|
||||
@@ -2012,8 +2012,6 @@ pub struct MacroDef {
|
||||
pub id: NodeId,
|
||||
pub span: Span,
|
||||
pub imported_from: Option<Ident>,
|
||||
pub export: bool,
|
||||
pub use_locally: bool,
|
||||
pub allow_internal_unstable: bool,
|
||||
pub body: Vec<TokenTree>,
|
||||
}
|
||||
|
||||
@@ -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<SyntaxExtension>);
|
||||
fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec<Mark>);
|
||||
|
||||
@@ -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<SyntaxExtension>) {}
|
||||
fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec<Mark>) {}
|
||||
|
||||
|
||||
@@ -157,14 +157,13 @@ impl IdentMacroExpander for MacroRulesExpander {
|
||||
tts: Vec<tokenstream::TokenTree>,
|
||||
attrs: Vec<ast::Attribute>)
|
||||
-> Box<MacResult> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user