Skip to content

Commit 53de24b

Browse files
committed
Refactor away fields MacroDef::{use_locally, export}.
1 parent e4baeaa commit 53de24b

File tree

8 files changed

+22
-34
lines changed

8 files changed

+22
-34
lines changed

src/librustc/hir/lowering.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,6 @@ impl<'a> LoweringContext<'a> {
716716
id: m.id,
717717
span: m.span,
718718
imported_from: m.imported_from.map(|x| x.name),
719-
export: m.export,
720-
use_locally: m.use_locally,
721719
allow_internal_unstable: m.allow_internal_unstable,
722720
body: m.body.clone().into(),
723721
}

src/librustc/hir/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ pub struct MacroDef {
458458
pub id: NodeId,
459459
pub span: Span,
460460
pub imported_from: Option<Name>,
461-
pub export: bool,
462-
pub use_locally: bool,
463461
pub allow_internal_unstable: bool,
464462
pub body: HirVec<TokenTree>,
465463
}

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,11 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
675675

676676
fn visit_macro_def(&mut self, macro_def: &'tcx MacroDef) {
677677
debug!("visit_macro_def: st={:?}", self.st);
678-
if macro_def.export {
679-
SawMacroDef.hash(self.st);
680-
hash_attrs!(self, &macro_def.attrs);
681-
visit::walk_macro_def(self, macro_def)
682-
// FIXME(mw): We should hash the body of the macro too but we don't
683-
// have a stable way of doing so yet.
684-
}
678+
SawMacroDef.hash(self.st);
679+
hash_attrs!(self, &macro_def.attrs);
680+
visit::walk_macro_def(self, macro_def)
681+
// FIXME(mw): We should hash the body of the macro too but we don't
682+
// have a stable way of doing so yet.
685683
}
686684
}
687685

src/librustc_metadata/creader.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,6 @@ impl<'a> CrateLoader<'a> {
594594
id: ast::DUMMY_NODE_ID,
595595
span: local_span,
596596
imported_from: Some(item.ident),
597-
// overridden in plugin/load.rs
598-
export: false,
599-
use_locally: false,
600597
allow_internal_unstable: attr::contains_name(&def.attrs, "allow_internal_unstable"),
601598
attrs: def.attrs,
602599
body: body,

src/librustc_resolve/macros.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,22 @@ impl<'a> base::Resolver for Resolver<'a> {
114114
invocation.expansion.set(visitor.legacy_scope);
115115
}
116116

117-
fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef) {
117+
fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef, export: bool) {
118118
if &def.ident.name.as_str() == "macro_rules" {
119119
self.session.span_err(def.span, "user-defined macros may not be named `macro_rules`");
120120
}
121-
if def.use_locally {
122-
let invocation = self.invocations[&scope];
123-
let binding = self.arenas.alloc_legacy_binding(LegacyBinding {
124-
parent: invocation.legacy_scope.get(),
125-
name: def.ident.name,
126-
ext: Rc::new(macro_rules::compile(&self.session.parse_sess, &def)),
127-
span: def.span,
128-
});
129-
invocation.legacy_scope.set(LegacyScope::Binding(binding));
130-
self.macro_names.insert(def.ident.name);
131-
}
132-
if def.export {
121+
122+
let invocation = self.invocations[&scope];
123+
let binding = self.arenas.alloc_legacy_binding(LegacyBinding {
124+
parent: invocation.legacy_scope.get(),
125+
name: def.ident.name,
126+
ext: Rc::new(macro_rules::compile(&self.session.parse_sess, &def)),
127+
span: def.span,
128+
});
129+
invocation.legacy_scope.set(LegacyScope::Binding(binding));
130+
self.macro_names.insert(def.ident.name);
131+
132+
if export {
133133
def.id = self.next_node_id();
134134
self.exported_macros.push(def);
135135
}

src/libsyntax/ast.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,8 +2012,6 @@ pub struct MacroDef {
20122012
pub id: NodeId,
20132013
pub span: Span,
20142014
pub imported_from: Option<Ident>,
2015-
pub export: bool,
2016-
pub use_locally: bool,
20172015
pub allow_internal_unstable: bool,
20182016
pub body: Vec<TokenTree>,
20192017
}

src/libsyntax/ext/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub trait Resolver {
519519
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
520520

521521
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion);
522-
fn add_macro(&mut self, scope: Mark, def: ast::MacroDef);
522+
fn add_macro(&mut self, scope: Mark, def: ast::MacroDef, export: bool);
523523
fn add_ext(&mut self, ident: ast::Ident, ext: Rc<SyntaxExtension>);
524524
fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec<Mark>);
525525

@@ -541,7 +541,7 @@ impl Resolver for DummyResolver {
541541
fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() }
542542

543543
fn visit_expansion(&mut self, _invoc: Mark, _expansion: &Expansion) {}
544-
fn add_macro(&mut self, _scope: Mark, _def: ast::MacroDef) {}
544+
fn add_macro(&mut self, _scope: Mark, _def: ast::MacroDef, _export: bool) {}
545545
fn add_ext(&mut self, _ident: ast::Ident, _ext: Rc<SyntaxExtension>) {}
546546
fn add_expansions_at_stmt(&mut self, _id: ast::NodeId, _macros: Vec<Mark>) {}
547547

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,13 @@ impl IdentMacroExpander for MacroRulesExpander {
157157
tts: Vec<tokenstream::TokenTree>,
158158
attrs: Vec<ast::Attribute>)
159159
-> Box<MacResult> {
160+
let export = attr::contains_name(&attrs, "macro_export");
160161
let def = ast::MacroDef {
161162
ident: ident,
162163
id: ast::DUMMY_NODE_ID,
163164
span: span,
164165
imported_from: None,
165-
use_locally: true,
166166
body: tts,
167-
export: attr::contains_name(&attrs, "macro_export"),
168167
allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"),
169168
attrs: attrs,
170169
};
@@ -176,7 +175,7 @@ impl IdentMacroExpander for MacroRulesExpander {
176175
MacEager::items(placeholders::macro_scope_placeholder().make_items())
177176
};
178177

179-
cx.resolver.add_macro(cx.current_expansion.mark, def);
178+
cx.resolver.add_macro(cx.current_expansion.mark, def, export);
180179
result
181180
}
182181
}

0 commit comments

Comments
 (0)