Skip to content

Commit 7ec01a6

Browse files
committed
Fortify find_entry.
1 parent b604b5e commit 7ec01a6

File tree

1 file changed

+10
-12
lines changed
  • compiler/rustc_middle/src/hir/map

1 file changed

+10
-12
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,17 @@ impl<'hir> Map<'hir> {
267267

268268
fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
269269
if id.local_id == ItemLocalId::from_u32(0) {
270-
let owner = self.tcx.hir_owner(id.owner);
271-
owner.map(|owner| Entry { parent: owner.parent, node: owner.node })
270+
let owner = self.tcx.hir_owner(id.owner)?;
271+
Some(Entry { parent: owner.parent, node: owner.node })
272272
} else {
273-
let owner = self.tcx.hir_owner_nodes(id.owner);
274-
owner.and_then(|owner| {
275-
let node = owner.nodes[id.local_id].as_ref();
276-
// FIXME(eddyb) use a single generic type insted of having both
277-
// `Entry` and `ParentedNode`, which are effectively the same.
278-
// Alternatively, rewrite code using `Entry` to use `ParentedNode`.
279-
node.map(|node| Entry {
280-
parent: HirId { owner: id.owner, local_id: node.parent },
281-
node: node.node,
282-
})
273+
let owner = self.tcx.hir_owner_nodes(id.owner)?;
274+
let node = owner.nodes.get(id.local_id)?.as_ref()?;
275+
// FIXME(eddyb) use a single generic type insted of having both
276+
// `Entry` and `ParentedNode`, which are effectively the same.
277+
// Alternatively, rewrite code using `Entry` to use `ParentedNode`.
278+
Some(Entry {
279+
parent: HirId { owner: id.owner, local_id: node.parent },
280+
node: node.node,
283281
})
284282
}
285283
}

0 commit comments

Comments
 (0)