From 6642462ef67c4ff4fbf55dce852f1b01ca3f9edf Mon Sep 17 00:00:00 2001 From: varkor Date: Sat, 25 Aug 2018 23:10:01 +0100 Subject: [PATCH] Make small modifications --- src/librustc/hir/map/collector.rs | 2 +- src/librustc/hir/map/mod.rs | 24 ++++++------------------ src/librustc/hir/mod.rs | 2 -- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 2cb8120836e..30441c331e4 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -115,7 +115,7 @@ pub(super) fn root(krate: &'hir Crate, hir_body_nodes, }; collector.insert_entry(CRATE_NODE_ID, Entry { - parent: ast::DUMMY_NODE_ID, + parent: CRATE_NODE_ID, dep_node: root_mod_sig_dep_index, node: Node::Crate, }); diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 747c1ac13dd..4f33120b46d 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -59,13 +59,6 @@ fn parent_node(self) -> Option { } } - fn to_node(self) -> Option> { - match self.node { - Node::Crate => None, - _ => Some(self.node), - } - } - fn fn_decl(&self) -> Option<&FnDecl> { match self.node { Node::Item(ref item) => { @@ -568,7 +561,7 @@ pub fn get_generics_span(&self, id: DefId) -> Option { /// Retrieve the Node corresponding to `id`, returning None if /// cannot be found. pub fn find(&self, id: NodeId) -> Option> { - let result = self.find_entry(id).and_then(|x| x.to_node()); + let result = self.find_entry(id).map(|x| x.node); if result.is_some() { self.read(id); } @@ -638,16 +631,11 @@ fn walk_parent_nodes(&self, return Err(id); } - if let Some(node) = self.find_entry(parent_node) { - match node.to_node() { - Some(ref node) => { - if found(node) { - return Ok(parent_node); - } else if bail_early(node) { - return Err(parent_node); - } - } - None => return Err(parent_node), + if let Some(entry) = self.find_entry(parent_node) { + if found(&entry.node) { + return Ok(parent_node); + } else if bail_early(&entry.node) { + return Err(parent_node); } id = parent_node; } else { diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index bae7fa391c0..7ac334d84a9 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2397,7 +2397,5 @@ pub enum Node<'hir> { GenericParam(&'hir GenericParam), Visibility(&'hir Visibility), - /// Roots for node trees. Its DepNodeIndex when in `Entry` - /// is the dependency node of the crate's root module. Crate, } -- GitLab