diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-01-18 19:15:53 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-01-23 13:58:09 +0100 |
| commit | 97ee7c7e5ab5b70453920e105530dd8a2a4391d9 (patch) | |
| tree | f6fa690d5f99f3c5e70fce3df6b4e5211c0f2738 | |
| parent | 89360931f23a512d76559a796cdbd74b6681c46e (diff) | |
| download | rust-97ee7c7e5ab5b70453920e105530dd8a2a4391d9.tar.gz rust-97ee7c7e5ab5b70453920e105530dd8a2a4391d9.zip | |
Allow to query the HIR crate node.
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/reachable.rs | 1 |
2 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 70819c9b3b5..9b01a64de84 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -252,6 +252,7 @@ impl<'hir> Map<'hir> { GenericParamKind::Type { .. } => DefKind::TyParam, GenericParamKind::Const { .. } => DefKind::ConstParam, }, + Node::Crate(_) => DefKind::Mod, Node::Stmt(_) | Node::PathSegment(_) | Node::Ty(_) @@ -263,8 +264,7 @@ impl<'hir> Map<'hir> { | Node::Arm(_) | Node::Lifetime(_) | Node::Visibility(_) - | Node::Block(_) - | Node::Crate(_) => return None, + | Node::Block(_) => return None, }; Some(def_kind) } @@ -523,9 +523,7 @@ impl<'hir> Map<'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 diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index b237671f8e2..eb24c51c54c 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -307,6 +307,7 @@ impl<'tcx> ReachableContext<'tcx> { | Node::Ctor(..) | Node::Field(_) | Node::Ty(_) + | Node::Crate(_) | Node::MacroDef(_) => {} _ => { bug!( |
