about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-10-25 22:05:02 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-11-10 09:21:44 +0000
commit85f74c0eea3667e85720d6f427709873eb576b49 (patch)
tree364154df487cf582628dc0efc5c478d26943a1f4 /src
parentdd0781ea254564cad86e3d594367b1988edf308d (diff)
Add variants `Def::Macro` and `Namespace::MacroNS`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/def.rs6
-rw-r--r--src/librustc_incremental/calculate_svh/svh_visitor.rs3
-rw-r--r--src/librustc_metadata/decoder.rs19
-rw-r--r--src/librustc_resolve/build_reduced_graph.rs5
-rw-r--r--src/librustc_resolve/lib.rs8
-rw-r--r--src/librustc_save_analysis/dump_visitor.rs1
-rw-r--r--src/librustc_save_analysis/lib.rs1
7 files changed, 36 insertions, 7 deletions
diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs
index 8b9cee1d2f6..044e36e5c9c 100644
--- a/src/librustc/hir/def.rs
+++ b/src/librustc/hir/def.rs
@@ -52,6 +52,9 @@ pub enum Def {
           ast::NodeId), // expr node that creates the closure
     Label(ast::NodeId),
 
+    // Macro namespace
+    Macro(DefId),
+
     // Both namespaces
     Err,
 }
@@ -133,7 +136,7 @@ impl Def {
             Def::Variant(id) | Def::VariantCtor(id, ..) | Def::Enum(id) | Def::TyAlias(id) |
             Def::AssociatedTy(id) | Def::TyParam(id) | Def::Struct(id) | Def::StructCtor(id, ..) |
             Def::Union(id) | Def::Trait(id) | Def::Method(id) | Def::Const(id) |
-            Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) => {
+            Def::AssociatedConst(id) | Def::Local(id) | Def::Upvar(id, ..) | Def::Macro(id) => {
                 id
             }
 
@@ -173,6 +176,7 @@ impl Def {
             Def::Upvar(..) => "closure capture",
             Def::Label(..) => "label",
             Def::SelfTy(..) => "self type",
+            Def::Macro(..) => "macro",
             Def::Err => "unresolved item",
         }
     }
diff --git a/src/librustc_incremental/calculate_svh/svh_visitor.rs b/src/librustc_incremental/calculate_svh/svh_visitor.rs
index 2358d60d0de..0b0dd596784 100644
--- a/src/librustc_incremental/calculate_svh/svh_visitor.rs
+++ b/src/librustc_incremental/calculate_svh/svh_visitor.rs
@@ -834,7 +834,8 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
             Def::Const(..) |
             Def::AssociatedConst(..) |
             Def::Local(..) |
-            Def::Upvar(..) => {
+            Def::Upvar(..) |
+            Def::Macro(..) => {
                 DefHash::SawDefId.hash(self.st);
                 self.hash_def_id(def.def_id());
             }
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index 1da26418965..8eae4658983 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -690,9 +690,7 @@ impl<'a, 'tcx> CrateMetadata {
     pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F)
         where F: FnMut(def::Export)
     {
-        if self.dep_kind.get() == DepKind::MacrosOnly {
-            return
-        }
+        let macros_only = self.dep_kind.get() == DepKind::MacrosOnly;
 
         // Find the item.
         let item = match self.maybe_entry(id) {
@@ -702,9 +700,19 @@ impl<'a, 'tcx> CrateMetadata {
 
         // Iterate over all children.
         for child_index in item.children.decode(self) {
+            if macros_only {
+                continue
+            }
+
             // Get the item.
             if let Some(child) = self.maybe_entry(child_index) {
                 let child = child.decode(self);
+                match child.kind {
+                    EntryKind::MacroDef(..) => {}
+                    _ if macros_only => continue,
+                    _ => {}
+                }
+
                 // Hand off the item to the callback.
                 match child.kind {
                     // FIXME(eddyb) Don't encode these in children.
@@ -763,6 +771,11 @@ impl<'a, 'tcx> CrateMetadata {
 
         if let EntryKind::Mod(data) = item.kind {
             for exp in data.decode(self).reexports.decode(self) {
+                match exp.def {
+                    Def::Macro(..) => {}
+                    _ if macros_only => continue,
+                    _ => {}
+                }
                 callback(exp);
             }
         }
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs
index ed87c61ef3b..5fb9809104f 100644
--- a/src/librustc_resolve/build_reduced_graph.rs
+++ b/src/librustc_resolve/build_reduced_graph.rs
@@ -17,7 +17,7 @@ use macros::{InvocationData, LegacyScope};
 use resolve_imports::ImportDirective;
 use resolve_imports::ImportDirectiveSubclass::{self, GlobImport};
 use {Module, ModuleS, ModuleKind};
-use Namespace::{self, TypeNS, ValueNS};
+use Namespace::{self, TypeNS, ValueNS, MacroNS};
 use {NameBinding, NameBindingKind, ToNameBinding};
 use Resolver;
 use {resolve_error, resolve_struct_error, ResolutionError};
@@ -485,6 +485,9 @@ impl<'b> Resolver<'b> {
                 let field_names = self.session.cstore.struct_field_names(def_id);
                 self.insert_field_names(def_id, field_names);
             }
+            Def::Macro(..) => {
+                self.define(parent, name, MacroNS, (def, DUMMY_SP, vis));
+            }
             Def::Local(..) |
             Def::PrimTy(..) |
             Def::TyParam(..) |
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 89a0826254c..31711c0526d 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -533,6 +533,7 @@ impl PatternSource {
 pub enum Namespace {
     TypeNS,
     ValueNS,
+    MacroNS,
 }
 
 impl<'a> Visitor for Resolver<'a> {
@@ -1346,7 +1347,11 @@ impl<'a> Resolver<'a> {
     }
 
     fn get_ribs<'b>(&'b mut self, ns: Namespace) -> &'b mut Vec<Rib<'a>> {
-        match ns { ValueNS => &mut self.value_ribs, TypeNS => &mut self.type_ribs }
+        match ns {
+            ValueNS => &mut self.value_ribs,
+            TypeNS => &mut self.type_ribs,
+            MacroNS => panic!("The macro namespace has no ribs"),
+        }
     }
 
     fn record_use(&mut self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>, span: Span)
@@ -3421,6 +3426,7 @@ impl<'a> Resolver<'a> {
         let msg = {
             let kind = match (ns, old_binding.module()) {
                 (ValueNS, _) => "a value",
+                (MacroNS, _) => "a macro",
                 (TypeNS, _) if old_binding.is_extern_crate() => "an extern crate",
                 (TypeNS, Ok(module)) if module.is_normal() => "a module",
                 (TypeNS, Ok(module)) if module.is_trait() => "a trait",
diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs
index 36c6a676013..e83c2359979 100644
--- a/src/librustc_save_analysis/dump_visitor.rs
+++ b/src/librustc_save_analysis/dump_visitor.rs
@@ -341,6 +341,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
             Def::AssociatedTy(..) |
             Def::AssociatedConst(..) |
             Def::PrimTy(_) |
+            Def::Macro(_) |
             Def::Err => {
                span_bug!(span,
                          "process_def_kind for unexpected item: {:?}",
diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs
index fded34d2c85..ab5bbea07a3 100644
--- a/src/librustc_save_analysis/lib.rs
+++ b/src/librustc_save_analysis/lib.rs
@@ -565,6 +565,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
             Def::PrimTy(..) |
             Def::SelfTy(..) |
             Def::Label(..) |
+            Def::Macro(..) |
             Def::Err => None,
         }
     }