]> git.lizzy.rs Git - rust.git/commitdiff
hir: replace NodeId with HirId in Destination
authorljedrz <ljedrz@gmail.com>
Thu, 7 Mar 2019 11:43:27 +0000 (12:43 +0100)
committerljedrz <ljedrz@gmail.com>
Thu, 7 Mar 2019 11:43:27 +0000 (12:43 +0100)
src/librustc/cfg/construct.rs
src/librustc/hir/intravisit.rs
src/librustc/hir/lowering.rs
src/librustc/hir/mod.rs
src/librustc/middle/liveness.rs
src/librustc_mir/hair/cx/expr.rs
src/librustc_passes/loops.rs
src/librustc_typeck/check/mod.rs

index 30a0477467d8016ff94d58cebc0a5174a2175239..e96709f6d14e5bd57b373786582ab9b6034715dc 100644 (file)
@@ -571,9 +571,9 @@ fn find_scope_edge(&self,
         match destination.target_id {
             Ok(loop_id) => {
                 for b in &self.breakable_block_scopes {
-                    if b.block_expr_id == self.tcx.hir().node_to_hir_id(loop_id).local_id {
+                    if b.block_expr_id == loop_id.local_id {
                         let scope = region::Scope {
-                            id: self.tcx.hir().node_to_hir_id(loop_id).local_id,
+                            id: loop_id.local_id,
                             data: region::ScopeData::Node
                         };
                         return (scope, match scope_cf_kind {
@@ -583,9 +583,9 @@ fn find_scope_edge(&self,
                     }
                 }
                 for l in &self.loop_scopes {
-                    if l.loop_id == self.tcx.hir().node_to_hir_id(loop_id).local_id {
+                    if l.loop_id == loop_id.local_id {
                         let scope = region::Scope {
-                            id: self.tcx.hir().node_to_hir_id(loop_id).local_id,
+                            id: loop_id.local_id,
                             data: region::ScopeData::Node
                         };
                         return (scope, match scope_cf_kind {
index 3c70df7461248968b1400a9d023fe7653c94afc9..bcfd832855cf7c1b11aafe2a673f8edeb6a0cc83 100644 (file)
@@ -1064,18 +1064,22 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
         ExprKind::Break(ref destination, ref opt_expr) => {
             if let Some(ref label) = destination.label {
                 visitor.visit_label(label);
+                /*
                 if let Ok(node_id) = destination.target_id {
                     visitor.visit_def_mention(Def::Label(node_id))
                 }
+                */
             }
             walk_list!(visitor, visit_expr, opt_expr);
         }
         ExprKind::Continue(ref destination) => {
             if let Some(ref label) = destination.label {
                 visitor.visit_label(label);
+                /*
                 if let Ok(node_id) = destination.target_id {
                     visitor.visit_def_mention(Def::Label(node_id))
                 }
+                */
             }
         }
         ExprKind::Ret(ref optional_expression) => {
index bcd2e500085cb7fb07701d5b809e55458c9bc3ea..949fdd2682b96dfcc62d328f26b4af63ddc83560 100644 (file)
@@ -1068,7 +1068,7 @@ fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hi
         let target_id = match destination {
             Some((id, _)) => {
                 if let Def::Label(loop_id) = self.expect_full_def(id) {
-                    Ok(self.lower_node_id(loop_id).node_id)
+                    Ok(self.lower_node_id(loop_id).hir_id)
                 } else {
                     Err(hir::LoopIdError::UnresolvedLabel)
                 }
@@ -1077,7 +1077,7 @@ fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hi
                 self.loop_scopes
                     .last()
                     .cloned()
-                    .map(|id| Ok(self.lower_node_id(id).node_id))
+                    .map(|id| Ok(self.lower_node_id(id).hir_id))
                     .unwrap_or(Err(hir::LoopIdError::OutsideLoopScope))
                     .into()
             }
@@ -4564,12 +4564,13 @@ fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
                     let thin_attrs = ThinVec::from(attrs);
                     let catch_scope = self.catch_scopes.last().map(|x| *x);
                     let ret_expr = if let Some(catch_node) = catch_scope {
+                        let target_id = Ok(self.lower_node_id(catch_node).hir_id);
                         P(self.expr(
                             e.span,
                             hir::ExprKind::Break(
                                 hir::Destination {
                                     label: None,
-                                    target_id: Ok(catch_node),
+                                    target_id,
                                 },
                                 Some(from_err_expr),
                             ),
index e24940f5f611e1257174d59a2ef33baf1a360929..1a8ea1e79941842db44bb9ff26e9ba26bd50c5c7 100644 (file)
@@ -1618,7 +1618,7 @@ pub struct Destination {
 
     // These errors are caught and then reported during the diagnostics pass in
     // librustc_passes/loops.rs
-    pub target_id: Result<NodeId, LoopIdError>,
+    pub target_id: Result<HirId, LoopIdError>,
 }
 
 #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
index 35b8e08a5d531fbe6482e0074f7c70d629f5427d..2fafc57ce4b2d193c5299d9126ab965ba346a042 100644 (file)
 use crate::ty::{self, TyCtxt};
 use crate::ty::query::Providers;
 use crate::lint;
-use crate::util::nodemap::{NodeMap, HirIdMap, HirIdSet};
+use crate::util::nodemap::{HirIdMap, HirIdSet};
 
 use errors::Applicability;
 use std::collections::{BTreeMap, VecDeque};
@@ -669,8 +669,8 @@ struct Liveness<'a, 'tcx: 'a> {
     // mappings from loop node ID to LiveNode
     // ("break" label should map to loop node ID,
     // it probably doesn't now)
-    break_ln: NodeMap<LiveNode>,
-    cont_ln: NodeMap<LiveNode>,
+    break_ln: HirIdMap<LiveNode>,
+    cont_ln: HirIdMap<LiveNode>,
 }
 
 impl<'a, 'tcx> Liveness<'a, 'tcx> {
@@ -951,8 +951,7 @@ fn compute(&mut self, body: &hir::Expr) -> LiveNode {
     fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode)
                                -> LiveNode {
         if blk.targeted_by_break {
-            let node_id = self.ir.tcx.hir().hir_to_node_id(blk.hir_id);
-            self.break_ln.insert(node_id, succ);
+            self.break_ln.insert(blk.hir_id, succ);
         }
         let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
         blk.stmts.iter().rev().fold(succ, |succ, stmt| {
@@ -1111,7 +1110,7 @@ fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode)
             hir::ExprKind::Break(label, ref opt_expr) => {
                 // Find which label this break jumps to
                 let target = match label.target_id {
-                    Ok(node_id) => self.break_ln.get(&node_id),
+                    Ok(hir_id) => self.break_ln.get(&hir_id),
                     Err(err) => span_bug!(expr.span, "loop scope error: {}", err),
                 }.cloned();
 
@@ -1390,15 +1389,14 @@ fn propagate_through_loop(&mut self,
         debug!("propagate_through_loop: using id for loop body {} {}",
                expr.hir_id, self.ir.tcx.hir().hir_to_pretty_string(body.hir_id));
 
-        let node_id = self.ir.tcx.hir().hir_to_node_id(expr.hir_id);
-        self.break_ln.insert(node_id, succ);
+        self.break_ln.insert(expr.hir_id, succ);
 
         let cond_ln = match kind {
             LoopLoop => ln,
             WhileLoop(ref cond) => self.propagate_through_expr(&cond, ln),
         };
 
-        self.cont_ln.insert(node_id, cond_ln);
+        self.cont_ln.insert(expr.hir_id, cond_ln);
 
         let body_ln = self.propagate_through_block(body, cond_ln);
 
index f1a22b222217919e71f0b861b438d6cdf26d02c0..6af45957acf0908984dedbe30f6efa6c05655423 100644 (file)
@@ -591,7 +591,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
             match dest.target_id {
                 Ok(target_id) => ExprKind::Break {
                     label: region::Scope {
-                        id: cx.tcx.hir().node_to_hir_id(target_id).local_id,
+                        id: target_id.local_id,
                         data: region::ScopeData::Node
                     },
                     value: value.to_ref(),
@@ -603,7 +603,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
             match dest.target_id {
                 Ok(loop_id) => ExprKind::Continue {
                     label: region::Scope {
-                        id: cx.tcx.hir().node_to_hir_id(loop_id).local_id,
+                        id: loop_id.local_id,
                         data: region::ScopeData::Node
                     },
                 },
index 533e043efa9d223f4f3f1addc239f21a25d58b46..2272ac97cddaa843466039d21228ee52080c2ab7 100644 (file)
@@ -8,7 +8,6 @@
 use rustc::hir::map::Map;
 use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
 use rustc::hir::{self, Node, Destination};
-use syntax::ast;
 use syntax::struct_span_err;
 use syntax_pos::Span;
 use errors::Applicability;
@@ -105,25 +104,25 @@ fn visit_expr(&mut self, e: &'hir hir::Expr) {
 
                 let loop_id = match label.target_id.into() {
                     Ok(loop_id) => loop_id,
-                    Err(hir::LoopIdError::OutsideLoopScope) => ast::DUMMY_NODE_ID,
+                    Err(hir::LoopIdError::OutsideLoopScope) => hir::DUMMY_HIR_ID,
                     Err(hir::LoopIdError::UnlabeledCfInWhileCondition) => {
                         self.emit_unlabled_cf_in_while_condition(e.span, "break");
-                        ast::DUMMY_NODE_ID
+                        hir::DUMMY_HIR_ID
                     },
-                    Err(hir::LoopIdError::UnresolvedLabel) => ast::DUMMY_NODE_ID,
+                    Err(hir::LoopIdError::UnresolvedLabel) => hir::DUMMY_HIR_ID,
                 };
 
-                if loop_id != ast::DUMMY_NODE_ID {
-                    if let Node::Block(_) = self.hir_map.find(loop_id).unwrap() {
+                if loop_id != hir::DUMMY_HIR_ID {
+                    if let Node::Block(_) = self.hir_map.find_by_hir_id(loop_id).unwrap() {
                         return
                     }
                 }
 
                 if opt_expr.is_some() {
-                    let loop_kind = if loop_id == ast::DUMMY_NODE_ID {
+                    let loop_kind = if loop_id == hir::DUMMY_HIR_ID {
                         None
                     } else {
-                        Some(match self.hir_map.expect_expr(loop_id).node {
+                        Some(match self.hir_map.expect_expr_by_hir_id(loop_id).node {
                             hir::ExprKind::While(..) => LoopKind::WhileLoop,
                             hir::ExprKind::Loop(_, _, source) => LoopKind::Loop(source),
                             ref r => span_bug!(e.span,
@@ -162,7 +161,7 @@ fn visit_expr(&mut self, e: &'hir hir::Expr) {
 
                 match destination.target_id {
                     Ok(loop_id) => {
-                        if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() {
+                        if let Node::Block(block) = self.hir_map.find_by_hir_id(loop_id).unwrap() {
                             struct_span_err!(self.sess, e.span, E0696,
                                             "`continue` pointing to a labeled block")
                                 .span_label(e.span,
index 423b2fd00210e17658d490793b72e248172d7531..2882ed47f12cc787805472c300528a04555cd48b 100644 (file)
@@ -4262,7 +4262,6 @@ fn check_expr_kind(
             }
             ExprKind::Break(destination, ref expr_opt) => {
                 if let Ok(target_id) = destination.target_id {
-                    let target_id = tcx.hir().node_to_hir_id(target_id);
                     let (e_ty, cause);
                     if let Some(ref e) = *expr_opt {
                         // If this is a break with a value, we need to type-check