librustc_middle: return LocalDefId instead of DefId in opt_local_def_id_from_node_id

This commit is contained in:
marmeladema 2020-04-08 12:22:19 +01:00
parent 96d77f0e5f
commit bc30e4dd4e
3 changed files with 16 additions and 14 deletions

View file

@ -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]

View file

@ -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 },

View 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).