Skip to content

Commit bc30e4d

Browse files
committed
librustc_middle: return LocalDefId instead of DefId in opt_local_def_id_from_node_id
1 parent 96d77f0 commit bc30e4d

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/librustc_middle/hir/map/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,16 @@ impl<'hir> Map<'hir> {
160160
// FIXME(eddyb) this function can and should return `LocalDefId`.
161161
#[inline]
162162
pub fn local_def_id_from_node_id(&self, node: NodeId) -> DefId {
163-
self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
164-
let hir_id = self.node_id_to_hir_id(node);
165-
bug!(
166-
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
167-
node,
168-
self.find_entry(hir_id)
169-
)
170-
})
163+
self.opt_local_def_id_from_node_id(node)
164+
.unwrap_or_else(|| {
165+
let hir_id = self.node_id_to_hir_id(node);
166+
bug!(
167+
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
168+
node,
169+
self.find_entry(hir_id)
170+
)
171+
})
172+
.to_def_id()
171173
}
172174

173175
// FIXME(eddyb) this function can and should return `LocalDefId`.
@@ -185,12 +187,12 @@ impl<'hir> Map<'hir> {
185187
#[inline]
186188
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<DefId> {
187189
let node_id = self.hir_id_to_node_id(hir_id);
188-
self.opt_local_def_id_from_node_id(node_id)
190+
Some(self.opt_local_def_id_from_node_id(node_id)?.to_def_id())
189191
}
190192

191193
#[inline]
192-
pub fn opt_local_def_id_from_node_id(&self, node: NodeId) -> Option<DefId> {
193-
Some(self.tcx.definitions.opt_local_def_id(node)?.to_def_id())
194+
pub fn opt_local_def_id_from_node_id(&self, node: NodeId) -> Option<LocalDefId> {
195+
self.tcx.definitions.opt_local_def_id(node)
194196
}
195197

196198
#[inline]

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
11341134
.tcx
11351135
.hir()
11361136
.opt_local_def_id_from_node_id(id)
1137-
.and_then(|id| self.save_ctxt.tcx.parent(id))
1137+
.and_then(|id| self.save_ctxt.tcx.parent(id.to_def_id()))
11381138
.map(id_from_def_id);
11391139

11401140
match use_tree.kind {
@@ -1273,7 +1273,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
12731273
.tcx
12741274
.hir()
12751275
.opt_local_def_id_from_node_id(item.id)
1276-
.and_then(|id| self.save_ctxt.tcx.parent(id))
1276+
.and_then(|id| self.save_ctxt.tcx.parent(id.to_def_id()))
12771277
.map(id_from_def_id);
12781278
self.dumper.import(
12791279
&Access { public: false, reachable: false },

src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {
10731073

10741074
fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
10751075
let def_id = scx.tcx.hir().opt_local_def_id_from_node_id(id);
1076-
def_id.map(id_from_def_id).unwrap_or_else(|| {
1076+
def_id.map(|id| id_from_def_id(id.to_def_id())).unwrap_or_else(|| {
10771077
// Create a *fake* `DefId` out of a `NodeId` by subtracting the `NodeId`
10781078
// out of the maximum u32 value. This will work unless you have *billions*
10791079
// of definitions in a single crate (very unlikely to actually happen).

0 commit comments

Comments
 (0)