about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2017-08-08 14:33:51 +0200
committerMichael Woerister <michaelwoerister@posteo>2017-08-11 12:11:38 +0200
commita8cf6cc6db13efea1057dfefbe9e6b583b23ea4f (patch)
tree5e943b51bf248fe44835849e2d1789af430f45de /src
parentfbc7398badef55d58476b5410e7e911bb872f537 (diff)
downloadrust-a8cf6cc6db13efea1057dfefbe9e6b583b23ea4f.tar.gz
rust-a8cf6cc6db13efea1057dfefbe9e6b583b23ea4f.zip
Add some ID conversion methods to HIR map and Definitions.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/map/definitions.rs13
-rw-r--r--src/librustc/hir/map/mod.rs10
2 files changed, 23 insertions, 0 deletions
diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs
index 67a4d71d90c..b371366bc5d 100644
--- a/src/librustc/hir/map/definitions.rs
+++ b/src/librustc/hir/map/definitions.rs
@@ -434,18 +434,22 @@ impl Definitions {
         DefPath::make(LOCAL_CRATE, index, |p| self.def_key(p))
     }
 
+    #[inline]
     pub fn opt_def_index(&self, node: ast::NodeId) -> Option<DefIndex> {
         self.node_to_def_index.get(&node).cloned()
     }
 
+    #[inline]
     pub fn opt_local_def_id(&self, node: ast::NodeId) -> Option<DefId> {
         self.opt_def_index(node).map(DefId::local)
     }
 
+    #[inline]
     pub fn local_def_id(&self, node: ast::NodeId) -> DefId {
         self.opt_local_def_id(node).unwrap()
     }
 
+    #[inline]
     pub fn as_local_node_id(&self, def_id: DefId) -> Option<ast::NodeId> {
         if def_id.krate == LOCAL_CRATE {
             let space_index = def_id.index.address_space().index();
@@ -461,6 +465,7 @@ impl Definitions {
         }
     }
 
+    #[inline]
     pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
         self.node_to_hir_id[node_id]
     }
@@ -473,6 +478,14 @@ impl Definitions {
             .unwrap()
     }
 
+    #[inline]
+    pub fn def_index_to_hir_id(&self, def_index: DefIndex) -> hir::HirId {
+        let space_index = def_index.address_space().index();
+        let array_index = def_index.as_array_index();
+        let node_id = self.def_index_to_node[space_index][array_index];
+        self.node_to_hir_id[node_id]
+    }
+
     /// Add a definition with a parent definition.
     pub fn create_root_def(&mut self,
                            crate_name: &str,
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index 3b73647f0eb..99ed4736a51 100644
--- a/src/librustc/hir/map/mod.rs
+++ b/src/librustc/hir/map/mod.rs
@@ -401,6 +401,16 @@ impl<'hir> Map<'hir> {
         self.definitions.node_to_hir_id(node_id)
     }
 
+    #[inline]
+    pub fn def_index_to_hir_id(&self, def_index: DefIndex) -> HirId {
+        self.definitions.def_index_to_hir_id(def_index)
+    }
+
+    #[inline]
+    pub fn def_index_to_node_id(&self, def_index: DefIndex) -> NodeId {
+        self.definitions.as_local_node_id(DefId::local(def_index)).unwrap()
+    }
+
     fn entry_count(&self) -> usize {
         self.map.len()
     }