Skip to content

Commit 85f74c0

Browse files
committed
Add variants Def::Macro and Namespace::MacroNS.
1 parent dd0781e commit 85f74c0

File tree

7 files changed

+36
-7
lines changed

7 files changed

+36
-7
lines changed

src/librustc/hir/def.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ pub enum Def {
5252
ast::NodeId), // expr node that creates the closure
5353
Label(ast::NodeId),
5454

55+
// Macro namespace
56+
Macro(DefId),
57+
5558
// Both namespaces
5659
Err,
5760
}
@@ -133,7 +136,7 @@ impl Def {
133136
Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::TyAlias(id) |
134137
Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
135138
Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
136-
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) => {
139+
Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id) => {
137140
id
138141
}
139142

@@ -173,6 +176,7 @@ impl Def {
173176
Def::Upvar(..) => "closure capture",
174177
Def::Label(..) => "label",
175178
Def::SelfTy(..) => "self type",
179+
Def::Macro(..) => "macro",
176180
Def::Err => "unresolved item",
177181
}
178182
}

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,8 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
834834
Def::Const(..) |
835835
Def::AssociatedConst(..) |
836836
Def::Local(..) |
837-
Def::Upvar(..) => {
837+
Def::Upvar(..) |
838+
Def::Macro(..) => {
838839
DefHash::SawDefId.hash(self.st);
839840
self.hash_def_id(def.def_id());
840841
}

src/librustc_metadata/decoder.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,7 @@ impl<'a, 'tcx> CrateMetadata {
690690
pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F)
691691
where F: FnMut(def::Export)
692692
{
693-
if self.dep_kind.get() == DepKind::MacrosOnly {
694-
return
695-
}
693+
let macros_only = self.dep_kind.get() == DepKind::MacrosOnly;
696694

697695
// Find the item.
698696
let item = match self.maybe_entry(id) {
@@ -702,9 +700,19 @@ impl<'a, 'tcx> CrateMetadata {
702700

703701
// Iterate over all children.
704702
for child_index in item.children.decode(self) {
703+
if macros_only {
704+
continue
705+
}
706+
705707
// Get the item.
706708
if let Some(child) = self.maybe_entry(child_index) {
707709
let child = child.decode(self);
710+
match child.kind {
711+
EntryKind::MacroDef(..) => {}
712+
_ if macros_only => continue,
713+
_ => {}
714+
}
715+
708716
// Hand off the item to the callback.
709717
match child.kind {
710718
// FIXME(eddyb) Don't encode these in children.
@@ -763,6 +771,11 @@ impl<'a, 'tcx> CrateMetadata {
763771

764772
if let EntryKind::Mod(data) = item.kind {
765773
for exp in data.decode(self).reexports.decode(self) {
774+
match exp.def {
775+
Def::Macro(..) => {}
776+
_ if macros_only => continue,
777+
_ => {}
778+
}
766779
callback(exp);
767780
}
768781
}

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use macros::{InvocationData, LegacyScope};
1717
use resolve_imports::ImportDirective;
1818
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport};
1919
use {Module, ModuleS, ModuleKind};
20-
use Namespace::{self, TypeNS, ValueNS};
20+
use Namespace::{self, TypeNS, ValueNS, MacroNS};
2121
use {NameBinding, NameBindingKind, ToNameBinding};
2222
use Resolver;
2323
use {resolve_error, resolve_struct_error, ResolutionError};
@@ -485,6 +485,9 @@ impl<'b> Resolver<'b> {
485485
let field_names = self.session.cstore.struct_field_names(def_id);
486486
self.insert_field_names(def_id, field_names);
487487
}
488+
Def::Macro(..) => {
489+
self.define(parent, name, MacroNS, (def, DUMMY_SP, vis));
490+
}
488491
Def::Local(..) |
489492
Def::PrimTy(..) |
490493
Def::TyParam(..) |

src/librustc_resolve/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ impl PatternSource {
533533
pub enum Namespace {
534534
TypeNS,
535535
ValueNS,
536+
MacroNS,
536537
}
537538

538539
impl<'a> Visitor for Resolver<'a> {
@@ -1346,7 +1347,11 @@ impl<'a> Resolver<'a> {
13461347
}
13471348

13481349
fn get_ribs<'b>(&'b mut self, ns: Namespace) -> &'b mut Vec<Rib<'a>> {
1349-
match ns { ValueNS => &mut self.value_ribs, TypeNS => &mut self.type_ribs }
1350+
match ns {
1351+
ValueNS => &mut self.value_ribs,
1352+
TypeNS => &mut self.type_ribs,
1353+
MacroNS => panic!("The macro namespace has no ribs"),
1354+
}
13501355
}
13511356

13521357
fn record_use(&mut self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>, span: Span)
@@ -3421,6 +3426,7 @@ impl<'a> Resolver<'a> {
34213426
let msg = {
34223427
let kind = match (ns, old_binding.module()) {
34233428
(ValueNS, _) => "a value",
3429+
(MacroNS, _) => "a macro",
34243430
(TypeNS, _) if old_binding.is_extern_crate() => "an extern crate",
34253431
(TypeNS, Ok(module)) if module.is_normal() => "a module",
34263432
(TypeNS, Ok(module)) if module.is_trait() => "a trait",

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
341341
Def::AssociatedTy(..) |
342342
Def::AssociatedConst(..) |
343343
Def::PrimTy(_) |
344+
Def::Macro(_) |
344345
Def::Err => {
345346
span_bug!(span,
346347
"process_def_kind for unexpected item: {:?}",

src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
565565
Def::PrimTy(..) |
566566
Def::SelfTy(..) |
567567
Def::Label(..) |
568+
Def::Macro(..) |
568569
Def::Err => None,
569570
}
570571
}

0 commit comments

Comments
 (0)