Skip to content

Commit 97ee7c7

Browse files
committed
Allow to query the HIR crate node.
1 parent 8936093 commit 97ee7c7

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ impl<'hir> Map<'hir> {
252252
GenericParamKind::Type { .. } => DefKind::TyParam,
253253
GenericParamKind::Const { .. } => DefKind::ConstParam,
254254
},
255+
Node::Crate(_) => DefKind::Mod,
255256
Node::Stmt(_)
256257
| Node::PathSegment(_)
257258
| Node::Ty(_)
@@ -263,8 +264,7 @@ impl<'hir> Map<'hir> {
263264
| Node::Arm(_)
264265
| Node::Lifetime(_)
265266
| Node::Visibility(_)
266-
| Node::Block(_)
267-
| Node::Crate(_) => return None,
267+
| Node::Block(_) => return None,
268268
};
269269
Some(def_kind)
270270
}
@@ -523,9 +523,7 @@ impl<'hir> Map<'hir> {
523523

524524
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
525525
pub fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
526-
self.find_entry(hir_id).and_then(|entry| {
527-
if let Node::Crate(..) = entry.node { None } else { Some(entry.node) }
528-
})
526+
self.find_entry(hir_id).map(|entry| entry.node)
529527
}
530528

531529
/// Similar to `get_parent`; returns the parent HIR Id, or just `hir_id` if there

compiler/rustc_passes/src/reachable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ impl<'tcx> ReachableContext<'tcx> {
307307
| Node::Ctor(..)
308308
| Node::Field(_)
309309
| Node::Ty(_)
310+
| Node::Crate(_)
310311
| Node::MacroDef(_) => {}
311312
_ => {
312313
bug!(

0 commit comments

Comments
 (0)