diff options
| author | marmeladema <xademax@gmail.com> | 2020-04-08 12:22:19 +0100 |
|---|---|---|
| committer | marmeladema <xademax@gmail.com> | 2020-04-10 12:13:54 +0100 |
| commit | bc30e4dd4ea85697c4e57621a298bee300ca1744 (patch) | |
| tree | f7047acc172ff17b5d232b1f189ae446de09ccc7 /src | |
| parent | 96d77f0e5f103612d62b85938aacfb33f5768433 (diff) | |
| download | rust-bc30e4dd4ea85697c4e57621a298bee300ca1744.tar.gz rust-bc30e4dd4ea85697c4e57621a298bee300ca1744.zip | |
librustc_middle: return LocalDefId instead of DefId in opt_local_def_id_from_node_id
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_middle/hir/map/mod.rs | 24 | ||||
| -rw-r--r-- | src/librustc_save_analysis/dump_visitor.rs | 4 | ||||
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 2 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/librustc_middle/hir/map/mod.rs b/src/librustc_middle/hir/map/mod.rs index e8ce13e06e9..343afab154b 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<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] diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 05eb524dff5..dc557fe3742 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 24b7be0c9b3..717f3ac35e7 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). |
