diff --git a/src/librustc_middle/hir/map/mod.rs b/src/librustc_middle/hir/map/mod.rs index e8ce13e06e9f..343afab154b4 100644 --- a/src/librustc_middle/hir/map/mod.rs +++ b/src/librustc_middle/hir/map/mod.rs @@ -160,14 +160,16 @@ impl<'hir> Map<'hir> { // 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 @@ impl<'hir> Map<'hir> { #[inline] pub fn opt_local_def_id(&self, hir_id: HirId) -> Option { 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 { - 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 { + self.tcx.definitions.opt_local_def_id(node) } #[inline] diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 05eb524dff5e..dc557fe37428 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1134,7 +1134,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> { .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 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> { .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 }, diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 24b7be0c9b30..717f3ac35e7f 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -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).