Skip to content

Commit e6d9d4b

Browse files
committed
Fortify find_entry.
1 parent fcdfaf0 commit e6d9d4b

File tree

1 file changed

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

1 file changed

+11
-12
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,18 @@ impl<'hir> Map<'hir> {
278278

279279
fn find_entry(&self, id: HirId) -> Option<Entry<'hir>> {
280280
if id.local_id == ItemLocalId::from_u32(0) {
281-
let owner = self.tcx.hir_owner(id.owner);
282-
owner.map(|owner| Entry { parent: owner.parent, node: owner.node })
281+
let owner = self.tcx.hir_owner(id.owner)?;
282+
Some(Entry { parent: owner.parent, node: owner.node })
283283
} else {
284-
let owner = self.tcx.hir_owner_nodes(id.owner);
285-
owner.and_then(|owner| {
286-
let node = owner.nodes[id.local_id].as_ref();
287-
// FIXME(eddyb) use a single generic type instead of having both
288-
// `Entry` and `ParentedNode`, which are effectively the same.
289-
// Alternatively, rewrite code using `Entry` to use `ParentedNode`.
290-
node.map(|node| Entry {
291-
parent: HirId { owner: id.owner, local_id: node.parent },
292-
node: node.node,
293-
})
284+
let owner = self.tcx.hir_owner_nodes(id.owner)?;
285+
let node = owner.nodes.get(id.local_id)?;
286+
let node = node.as_ref()?;
287+
// FIXME(eddyb) use a single generic type instead of having both
288+
// `Entry` and `ParentedNode`, which are effectively the same.
289+
// Alternatively, rewrite code using `Entry` to use `ParentedNode`.
290+
Some(Entry {
291+
parent: HirId { owner: id.owner, local_id: node.parent },
292+
node: node.node,
294293
})
295294
}
296295
}

0 commit comments

Comments
 (0)