Allow to query the HIR crate node.

This commit is contained in:
Camille GILLOT 2021-01-18 19:15:53 +01:00
parent 89360931f2
commit 97ee7c7e5a
2 changed files with 4 additions and 5 deletions

View File

@ -252,6 +252,7 @@ pub fn opt_def_kind(&self, local_def_id: LocalDefId) -> Option<DefKind> {
GenericParamKind::Type { .. } => DefKind::TyParam,
GenericParamKind::Const { .. } => DefKind::ConstParam,
},
Node::Crate(_) => DefKind::Mod,
Node::Stmt(_)
| Node::PathSegment(_)
| Node::Ty(_)
@ -263,8 +264,7 @@ pub fn opt_def_kind(&self, local_def_id: LocalDefId) -> Option<DefKind> {
| Node::Arm(_)
| Node::Lifetime(_)
| Node::Visibility(_)
| Node::Block(_)
| Node::Crate(_) => return None,
| Node::Block(_) => return None,
};
Some(def_kind)
}
@ -523,9 +523,7 @@ pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
pub fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
self.find_entry(hir_id).and_then(|entry| {
if let Node::Crate(..) = entry.node { None } else { Some(entry.node) }
})
self.find_entry(hir_id).map(|entry| entry.node)
}
/// Similar to `get_parent`; returns the parent HIR Id, or just `hir_id` if there

View File

@ -307,6 +307,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>, search_item: LocalDefId) {
| Node::Ctor(..)
| Node::Field(_)
| Node::Ty(_)
| Node::Crate(_)
| Node::MacroDef(_) => {}
_ => {
bug!(