]> git.lizzy.rs Git - rust.git/commitdiff
librustc_middle: return LocalDefId instead of DefId in opt_local_def_id_from_node_id
authormarmeladema <xademax@gmail.com>
Wed, 8 Apr 2020 11:22:19 +0000 (12:22 +0100)
committermarmeladema <xademax@gmail.com>
Fri, 10 Apr 2020 11:13:54 +0000 (12:13 +0100)
src/librustc_middle/hir/map/mod.rs
src/librustc_save_analysis/dump_visitor.rs
src/librustc_save_analysis/lib.rs

index e8ce13e06e9f55b62a36e666d14a7ac56d4d2fd3..343afab154b44d4afbc71c9bb92a1c5a5772e40d 100644 (file)
@@ -160,14 +160,16 @@ pub fn def_path(&self, def_id: LocalDefId) -> DefPath {
     // FIXME(eddyb) this function can and should return `LocalDefId`.
     #[inline]
     pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
-        self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
-            let hir_id = self.node_id_to_hir_id(node);
-            bug!(
-                "local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
-                node,
-                self.find_entry(hir_id)
-            )
-        })
+        self.opt_local_def_id_from_node_id(node)
+            .unwrap_or_else(|| {
+                let hir_id = self.node_id_to_hir_id(node);
+                bug!(
+                    "local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
+                    node,
+                    self.find_entry(hir_id)
+                )
+            })
+            .to_def_id()
     }
 
     // FIXME(eddyb) this function can and should return `LocalDefId`.
@@ -185,12 +187,12 @@ pub fn local_def_id(&self, hir_id: HirId) -> DefId {
     #[inline]
     pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
         let node_id = self.hir_id_to_node_id(hir_id);
-        self.opt_local_def_id_from_node_id(node_id)
+        Some(self.opt_local_def_id_from_node_id(node_id)?.to_def_id())
     }
 
     #[inline]
-    pub fn opt_local_def_id_from_node_id(&self, node: NodeId) -> Option<DefId> {
-        Some(self.tcx.definitions.opt_local_def_id(node)?.to_def_id())
+    pub fn opt_local_def_id_from_node_id(&self, node: NodeId) -> Option<LocalDefId> {
+        self.tcx.definitions.opt_local_def_id(node)
     }
 
     #[inline]
index 05eb524dff5e341b79acf6bad39a382c6154b2b3..dc557fe37428a312824b238e91e523deb70b6076 100644 (file)
@@ -1134,7 +1134,7 @@ fn process_use_tree(
             .tcx
             .hir()
             .opt_local_def_id_from_node_id(id)
-            .and_then(|id| self.save_ctxt.tcx.parent(id))
+            .and_then(|id| self.save_ctxt.tcx.parent(id.to_def_id()))
             .map(id_from_def_id);
 
         match use_tree.kind {
@@ -1273,7 +1273,7 @@ fn visit_item(&mut self, item: &'l ast::Item) {
                         .tcx
                         .hir()
                         .opt_local_def_id_from_node_id(item.id)
-                        .and_then(|id| self.save_ctxt.tcx.parent(id))
+                        .and_then(|id| self.save_ctxt.tcx.parent(id.to_def_id()))
                         .map(id_from_def_id);
                     self.dumper.import(
                         &Access { public: false, reachable: false },
index 24b7be0c9b306de9f8b4fd05fff44a1ca4bd36e5..717f3ac35e7f0edf00397278dd484c3f3133cc50 100644 (file)
@@ -1073,7 +1073,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {
 
 fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
     let def_id = scx.tcx.hir().opt_local_def_id_from_node_id(id);
-    def_id.map(id_from_def_id).unwrap_or_else(|| {
+    def_id.map(|id| id_from_def_id(id.to_def_id())).unwrap_or_else(|| {
         // Create a *fake* `DefId` out of a `NodeId` by subtracting the `NodeId`
         // out of the maximum u32 value. This will work unless you have *billions*
         // of definitions in a single crate (very unlikely to actually happen).