about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-11-23 18:19:57 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-11-23 18:19:57 +0300
commitbbbdbb0e44bb4cea653584017acce4bcda158939 (patch)
tree787ce80988a2f3416a9471ede25bd8310a96c4ac /src
parent9420ff4c0ebea44b167d530bb59f9d5721d8ff0b (diff)
downloadrust-bbbdbb0e44bb4cea653584017acce4bcda158939.tar.gz
rust-bbbdbb0e44bb4cea653584017acce4bcda158939.zip
Move def collector from `rustc` to `rustc_resolve`
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/map/definitions.rs11
-rw-r--r--src/librustc/hir/map/mod.rs2
-rw-r--r--src/librustc_resolve/build_reduced_graph.rs5
-rw-r--r--src/librustc_resolve/def_collector.rs (renamed from src/librustc/hir/map/def_collector.rs)27
-rw-r--r--src/librustc_resolve/lib.rs1
5 files changed, 29 insertions, 17 deletions
diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs
index 2b3bc37c87c..91b4971cd92 100644
--- a/src/librustc/hir/map/definitions.rs
+++ b/src/librustc/hir/map/definitions.rs
@@ -105,7 +105,7 @@ pub struct Definitions {
     /// we know what parent node that fragment should be attached to thanks to this table.
     invocation_parents: FxHashMap<ExpnId, DefIndex>,
     /// Indices of unnamed struct or variant fields with unresolved attributes.
-    pub(super) placeholder_field_indices: NodeMap<usize>,
+    placeholder_field_indices: NodeMap<usize>,
 }
 
 /// A unique identifier that we can use to lookup a definition
@@ -535,6 +535,15 @@ impl Definitions {
         let old_parent = self.invocation_parents.insert(invoc_id, parent);
         assert!(old_parent.is_none(), "parent `DefIndex` is reset for an invocation");
     }
+
+    pub fn placeholder_field_index(&self, node_id: ast::NodeId) -> usize {
+        self.placeholder_field_indices[&node_id]
+    }
+
+    pub fn set_placeholder_field_index(&mut self, node_id: ast::NodeId, index: usize) {
+        let old_index = self.placeholder_field_indices.insert(node_id, index);
+        assert!(old_index.is_none(), "placeholder field index is reset for a node ID");
+    }
 }
 
 impl DefPathData {
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index 83372dd8ade..fc754c5e675 100644
--- a/src/librustc/hir/map/mod.rs
+++ b/src/librustc/hir/map/mod.rs
@@ -1,5 +1,4 @@
 use self::collector::NodeCollector;
-pub use self::def_collector::DefCollector;
 pub use self::definitions::{
     Definitions, DefKey, DefPath, DefPathData, DisambiguatedDefPathData, DefPathHash
 };
@@ -25,7 +24,6 @@ use syntax_pos::{Span, DUMMY_SP};
 
 pub mod blocks;
 mod collector;
-mod def_collector;
 pub mod definitions;
 mod hir_id_validator;
 
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs
index fd401fde204..a178c603a46 100644
--- a/src/librustc_resolve/build_reduced_graph.rs
+++ b/src/librustc_resolve/build_reduced_graph.rs
@@ -5,6 +5,7 @@
 //! unexpanded macros in the fragment are visited and registered.
 //! Imports are also considered items and placed into modules here, but not resolved yet.
 
+use crate::def_collector::collect_definitions;
 use crate::macros::{LegacyBinding, LegacyScope};
 use crate::resolve_imports::ImportDirective;
 use crate::resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
@@ -16,7 +17,6 @@ use crate::{ResolutionError, Determinacy, PathResult, CrateLint};
 use rustc::bug;
 use rustc::hir::def::{self, *};
 use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
-use rustc::hir::map::DefCollector;
 use rustc::ty;
 use rustc::middle::cstore::CrateStore;
 use rustc_metadata::cstore::LoadedMacro;
@@ -167,8 +167,7 @@ impl<'a> Resolver<'a> {
         fragment: &AstFragment,
         parent_scope: ParentScope<'a>,
     ) -> LegacyScope<'a> {
-        let mut def_collector = DefCollector::new(&mut self.definitions, parent_scope.expansion);
-        fragment.visit_with(&mut def_collector);
+        collect_definitions(&mut self.definitions, fragment, parent_scope.expansion);
         let mut visitor = BuildReducedGraphVisitor { r: self, parent_scope };
         fragment.visit_with(&mut visitor);
         visitor.parent_scope.legacy
diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc_resolve/def_collector.rs
index cfd90f50b1b..414ea6e9aa1 100644
--- a/src/librustc/hir/map/def_collector.rs
+++ b/src/librustc_resolve/def_collector.rs
@@ -1,26 +1,31 @@
-use crate::hir::map::definitions::*;
-use crate::hir::def_id::DefIndex;
-
+use log::debug;
+use rustc::hir::map::definitions::*;
+use rustc::hir::def_id::DefIndex;
 use syntax::ast::*;
 use syntax::visit;
 use syntax::symbol::{kw, sym};
 use syntax::token::{self, Token};
+use syntax_expand::expand::AstFragment;
 use syntax_pos::hygiene::ExpnId;
 use syntax_pos::Span;
 
+crate fn collect_definitions(
+    definitions: &mut Definitions,
+    fragment: &AstFragment,
+    expansion: ExpnId,
+) {
+    let parent_def = definitions.invocation_parent(expansion);
+    fragment.visit_with(&mut DefCollector { definitions, parent_def, expansion });
+}
+
 /// Creates `DefId`s for nodes in the AST.
-pub struct DefCollector<'a> {
+struct DefCollector<'a> {
     definitions: &'a mut Definitions,
     parent_def: DefIndex,
     expansion: ExpnId,
 }
 
 impl<'a> DefCollector<'a> {
-    pub fn new(definitions: &'a mut Definitions, expansion: ExpnId) -> Self {
-        let parent_def = definitions.invocation_parent(expansion);
-        DefCollector { definitions, parent_def, expansion }
-    }
-
     fn create_def(&mut self,
                   node_id: NodeId,
                   data: DefPathData,
@@ -82,7 +87,7 @@ impl<'a> DefCollector<'a> {
                 .or_else(|| index.map(sym::integer))
                 .unwrap_or_else(|| {
                     let node_id = NodeId::placeholder_from_expn_id(self.expansion);
-                    sym::integer(self.definitions.placeholder_field_indices[&node_id])
+                    sym::integer(self.definitions.placeholder_field_index(node_id))
                 });
             let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
             self.with_parent(def, |this| visit::walk_struct_field(this, field));
@@ -186,7 +191,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
         for (index, field) in data.fields().iter().enumerate() {
             self.collect_field(field, Some(index));
             if field.is_placeholder && field.ident.is_none() {
-                self.definitions.placeholder_field_indices.insert(field.id, index);
+                self.definitions.set_placeholder_field_index(field.id, index);
             }
         }
     }
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index c49db39643b..347b7288565 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -68,6 +68,7 @@ use rustc_error_codes::*;
 
 type Res = def::Res<NodeId>;
 
+mod def_collector;
 mod diagnostics;
 mod late;
 mod macros;