From 47dc349491e18a824a922c7bea4db3c26880c07f Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 15 Feb 2019 15:21:56 +0100 Subject: [PATCH] adjust intravisit HirIdification --- src/librustc/hir/map/collector.rs | 21 ++++++++++----------- src/librustc/hir/map/hir_id_validator.rs | 7 ++----- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 5b3e9873353..04eec88004a 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -27,7 +27,7 @@ pub(super) struct NodeCollector<'a, 'hir> { /// The node map map: Vec>>, /// The parent of this node - parent_hir: hir::HirId, + parent_node: hir::HirId, // These fields keep track of the currently relevant DepNodes during // the visitor's traversal. @@ -147,7 +147,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { krate, source_map: sess.source_map(), map: repeat(None).take(sess.current_node_id_count()).collect(), - parent_hir: hir::CRATE_HIR_ID, + parent_node: hir::CRATE_HIR_ID, current_signature_dep_index: root_mod_sig_dep_index, current_full_dep_index: root_mod_full_dep_index, current_dep_node_owner: CRATE_DEF_INDEX, @@ -230,8 +230,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { fn insert(&mut self, span: Span, hir_id: HirId, node: Node<'hir>) { let entry = Entry { - parent: self.hir_to_node_id[&self.parent_hir], - parent_hir: self.parent_hir, + parent: self.hir_to_node_id[&self.parent_node], + parent_hir: self.parent_node, dep_node: if self.currently_in_body { self.current_full_dep_index } else { @@ -283,13 +283,13 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { fn with_parent( &mut self, - parent_hir_id: HirId, + parent_node_id: HirId, f: F, ) { - let parent_hir = self.parent_hir; - self.parent_hir = parent_hir_id; + let parent_node = self.parent_node; + self.parent_node = parent_node_id; f(self); - self.parent_hir = parent_hir; + self.parent_node = parent_node; } fn with_dep_node_owner HashStable>, @@ -446,8 +446,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment) { - if path_segment.id.is_some() { - let hir_id = path_segment.hir_id.unwrap(); + if let Some(hir_id) = path_segment.hir_id { self.insert(path_span, hir_id, Node::PathSegment(path_segment)); } intravisit::walk_path_segment(self, path_span, path_segment); @@ -471,7 +470,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { fn visit_fn(&mut self, fk: intravisit::FnKind<'hir>, fd: &'hir FnDecl, b: BodyId, s: Span, id: HirId) { - assert_eq!(self.parent_hir, id); + assert_eq!(self.parent_node, id); intravisit::walk_fn(self, fk, fd, b, s, id); } diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index dc146a8bc09..fafe671b9eb 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -98,11 +98,8 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { if max != self.hir_ids_seen.len() - 1 { // Collect the missing ItemLocalIds let missing: Vec<_> = (0 ..= max as u32) - .filter(|&i| !self.hir_ids_seen - .iter() - .find(|&local_id| local_id == &ItemLocalId::from_u32(i)) - .is_some() - ).collect(); + .filter(|&i| !self.hir_ids_seen.contains(&ItemLocalId::from_u32(i))) + .collect(); // Try to map those to something more useful let mut missing_items = Vec::with_capacity(missing.len());