Refactor away fields MacroDef::{use_locally, export}.
This commit is contained in:
@@ -716,8 +716,6 @@ impl<'a> LoweringContext<'a> {
|
|||||||
id: m.id,
|
id: m.id,
|
||||||
span: m.span,
|
span: m.span,
|
||||||
imported_from: m.imported_from.map(|x| x.name),
|
imported_from: m.imported_from.map(|x| x.name),
|
||||||
export: m.export,
|
|
||||||
use_locally: m.use_locally,
|
|
||||||
allow_internal_unstable: m.allow_internal_unstable,
|
allow_internal_unstable: m.allow_internal_unstable,
|
||||||
body: m.body.clone().into(),
|
body: m.body.clone().into(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -458,8 +458,6 @@ pub struct MacroDef {
|
|||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub imported_from: Option<Name>,
|
pub imported_from: Option<Name>,
|
||||||
pub export: bool,
|
|
||||||
pub use_locally: bool,
|
|
||||||
pub allow_internal_unstable: bool,
|
pub allow_internal_unstable: bool,
|
||||||
pub body: HirVec<TokenTree>,
|
pub body: HirVec<TokenTree>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -675,7 +675,6 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
|
|||||||
|
|
||||||
fn visit_macro_def(&mut self, macro_def: &'tcx MacroDef) {
|
fn visit_macro_def(&mut self, macro_def: &'tcx MacroDef) {
|
||||||
debug!("visit_macro_def: st={:?}", self.st);
|
debug!("visit_macro_def: st={:?}", self.st);
|
||||||
if macro_def.export {
|
|
||||||
SawMacroDef.hash(self.st);
|
SawMacroDef.hash(self.st);
|
||||||
hash_attrs!(self, ¯o_def.attrs);
|
hash_attrs!(self, ¯o_def.attrs);
|
||||||
visit::walk_macro_def(self, macro_def)
|
visit::walk_macro_def(self, macro_def)
|
||||||
@@ -683,7 +682,6 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
|
|||||||
// have a stable way of doing so yet.
|
// have a stable way of doing so yet.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Hash)]
|
#[derive(Hash)]
|
||||||
pub enum DefHash {
|
pub enum DefHash {
|
||||||
|
|||||||
@@ -594,9 +594,6 @@ impl<'a> CrateLoader<'a> {
|
|||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
span: local_span,
|
span: local_span,
|
||||||
imported_from: Some(item.ident),
|
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"),
|
allow_internal_unstable: attr::contains_name(&def.attrs, "allow_internal_unstable"),
|
||||||
attrs: def.attrs,
|
attrs: def.attrs,
|
||||||
body: body,
|
body: body,
|
||||||
|
|||||||
@@ -114,11 +114,11 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||||||
invocation.expansion.set(visitor.legacy_scope);
|
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" {
|
if &def.ident.name.as_str() == "macro_rules" {
|
||||||
self.session.span_err(def.span, "user-defined macros may not be named `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 invocation = self.invocations[&scope];
|
||||||
let binding = self.arenas.alloc_legacy_binding(LegacyBinding {
|
let binding = self.arenas.alloc_legacy_binding(LegacyBinding {
|
||||||
parent: invocation.legacy_scope.get(),
|
parent: invocation.legacy_scope.get(),
|
||||||
@@ -128,8 +128,8 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||||||
});
|
});
|
||||||
invocation.legacy_scope.set(LegacyScope::Binding(binding));
|
invocation.legacy_scope.set(LegacyScope::Binding(binding));
|
||||||
self.macro_names.insert(def.ident.name);
|
self.macro_names.insert(def.ident.name);
|
||||||
}
|
|
||||||
if def.export {
|
if export {
|
||||||
def.id = self.next_node_id();
|
def.id = self.next_node_id();
|
||||||
self.exported_macros.push(def);
|
self.exported_macros.push(def);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2012,8 +2012,6 @@ pub struct MacroDef {
|
|||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub imported_from: Option<Ident>,
|
pub imported_from: Option<Ident>,
|
||||||
pub export: bool,
|
|
||||||
pub use_locally: bool,
|
|
||||||
pub allow_internal_unstable: bool,
|
pub allow_internal_unstable: bool,
|
||||||
pub body: Vec<TokenTree>,
|
pub body: Vec<TokenTree>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -519,7 +519,7 @@ pub trait Resolver {
|
|||||||
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
|
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
|
||||||
|
|
||||||
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion);
|
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_ext(&mut self, ident: ast::Ident, ext: Rc<SyntaxExtension>);
|
||||||
fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec<Mark>);
|
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 get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() }
|
||||||
|
|
||||||
fn visit_expansion(&mut self, _invoc: Mark, _expansion: &Expansion) {}
|
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_ext(&mut self, _ident: ast::Ident, _ext: Rc<SyntaxExtension>) {}
|
||||||
fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec<Mark>) {}
|
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>,
|
tts: Vec<tokenstream::TokenTree>,
|
||||||
attrs: Vec<ast::Attribute>)
|
attrs: Vec<ast::Attribute>)
|
||||||
-> Box<MacResult> {
|
-> Box<MacResult> {
|
||||||
|
let export = attr::contains_name(&attrs, "macro_export");
|
||||||
let def = ast::MacroDef {
|
let def = ast::MacroDef {
|
||||||
ident: ident,
|
ident: ident,
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
span: span,
|
span: span,
|
||||||
imported_from: None,
|
imported_from: None,
|
||||||
use_locally: true,
|
|
||||||
body: tts,
|
body: tts,
|
||||||
export: attr::contains_name(&attrs, "macro_export"),
|
|
||||||
allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"),
|
allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"),
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
};
|
};
|
||||||
@@ -176,7 +175,7 @@ impl IdentMacroExpander for MacroRulesExpander {
|
|||||||
MacEager::items(placeholders::macro_scope_placeholder().make_items())
|
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
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user