Skip to content

Commit 42fbcb5

Browse files
committed
hir: replace NodeId with HirId in Destination
1 parent 558a07b commit 42fbcb5

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

src/librustc/cfg/construct.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
571571
match destination.target_id {
572572
Ok(loop_id) => {
573573
for b in &self.breakable_block_scopes {
574-
if b.block_expr_id == self.tcx.hir().node_to_hir_id(loop_id).local_id {
574+
if b.block_expr_id == loop_id.local_id {
575575
let scope = region::Scope {
576-
id: self.tcx.hir().node_to_hir_id(loop_id).local_id,
576+
id: loop_id.local_id,
577577
data: region::ScopeData::Node
578578
};
579579
return (scope, match scope_cf_kind {
@@ -583,9 +583,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
583583
}
584584
}
585585
for l in &self.loop_scopes {
586-
if l.loop_id == self.tcx.hir().node_to_hir_id(loop_id).local_id {
586+
if l.loop_id == loop_id.local_id {
587587
let scope = region::Scope {
588-
id: self.tcx.hir().node_to_hir_id(loop_id).local_id,
588+
id: loop_id.local_id,
589589
data: region::ScopeData::Node
590590
};
591591
return (scope, match scope_cf_kind {

src/librustc/hir/intravisit.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1064,18 +1064,22 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10641064
ExprKind::Break(ref destination, ref opt_expr) => {
10651065
if let Some(ref label) = destination.label {
10661066
visitor.visit_label(label);
1067+
/*
10671068
if let Ok(node_id) = destination.target_id {
10681069
visitor.visit_def_mention(Def::Label(node_id))
10691070
}
1071+
*/
10701072
}
10711073
walk_list!(visitor, visit_expr, opt_expr);
10721074
}
10731075
ExprKind::Continue(ref destination) => {
10741076
if let Some(ref label) = destination.label {
10751077
visitor.visit_label(label);
1078+
/*
10761079
if let Ok(node_id) = destination.target_id {
10771080
visitor.visit_def_mention(Def::Label(node_id))
10781081
}
1082+
*/
10791083
}
10801084
}
10811085
ExprKind::Ret(ref optional_expression) => {

src/librustc/hir/lowering.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ impl<'a> LoweringContext<'a> {
10681068
let target_id = match destination {
10691069
Some((id, _)) => {
10701070
if let Def::Label(loop_id) = self.expect_full_def(id) {
1071-
Ok(self.lower_node_id(loop_id).node_id)
1071+
Ok(self.lower_node_id(loop_id).hir_id)
10721072
} else {
10731073
Err(hir::LoopIdError::UnresolvedLabel)
10741074
}
@@ -1077,7 +1077,7 @@ impl<'a> LoweringContext<'a> {
10771077
self.loop_scopes
10781078
.last()
10791079
.cloned()
1080-
.map(|id| Ok(self.lower_node_id(id).node_id))
1080+
.map(|id| Ok(self.lower_node_id(id).hir_id))
10811081
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope))
10821082
.into()
10831083
}
@@ -4564,12 +4564,13 @@ impl<'a> LoweringContext<'a> {
45644564
let thin_attrs = ThinVec::from(attrs);
45654565
let catch_scope = self.catch_scopes.last().map(|x| *x);
45664566
let ret_expr = if let Some(catch_node) = catch_scope {
4567+
let target_id = Ok(self.lower_node_id(catch_node).hir_id);
45674568
P(self.expr(
45684569
e.span,
45694570
hir::ExprKind::Break(
45704571
hir::Destination {
45714572
label: None,
4572-
target_id: Ok(catch_node),
4573+
target_id,
45734574
},
45744575
Some(from_err_expr),
45754576
),

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ pub struct Destination {
16181618

16191619
// These errors are caught and then reported during the diagnostics pass in
16201620
// librustc_passes/loops.rs
1621-
pub target_id: Result<NodeId, LoopIdError>,
1621+
pub target_id: Result<HirId, LoopIdError>,
16221622
}
16231623

16241624
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]

src/librustc/middle/liveness.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ use crate::hir::Node;
102102
use crate::ty::{self, TyCtxt};
103103
use crate::ty::query::Providers;
104104
use crate::lint;
105-
use crate::util::nodemap::{NodeMap, HirIdMap, HirIdSet};
105+
use crate::util::nodemap::{HirIdMap, HirIdSet};
106106

107107
use errors::Applicability;
108108
use std::collections::{BTreeMap, VecDeque};
@@ -669,8 +669,8 @@ struct Liveness<'a, 'tcx: 'a> {
669669
// mappings from loop node ID to LiveNode
670670
// ("break" label should map to loop node ID,
671671
// it probably doesn't now)
672-
break_ln: NodeMap<LiveNode>,
673-
cont_ln: NodeMap<LiveNode>,
672+
break_ln: HirIdMap<LiveNode>,
673+
cont_ln: HirIdMap<LiveNode>,
674674
}
675675

676676
impl<'a, 'tcx> Liveness<'a, 'tcx> {
@@ -951,8 +951,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
951951
fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode)
952952
-> LiveNode {
953953
if blk.targeted_by_break {
954-
let node_id = self.ir.tcx.hir().hir_to_node_id(blk.hir_id);
955-
self.break_ln.insert(node_id, succ);
954+
self.break_ln.insert(blk.hir_id, succ);
956955
}
957956
let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
958957
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
@@ -1111,7 +1110,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11111110
hir::ExprKind::Break(label, ref opt_expr) => {
11121111
// Find which label this break jumps to
11131112
let target = match label.target_id {
1114-
Ok(node_id) => self.break_ln.get(&node_id),
1113+
Ok(hir_id) => self.break_ln.get(&hir_id),
11151114
Err(err) => span_bug!(expr.span, "loop scope error: {}", err),
11161115
}.cloned();
11171116

@@ -1390,15 +1389,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13901389
debug!("propagate_through_loop: using id for loop body {} {}",
13911390
expr.hir_id, self.ir.tcx.hir().hir_to_pretty_string(body.hir_id));
13921391

1393-
let node_id = self.ir.tcx.hir().hir_to_node_id(expr.hir_id);
1394-
self.break_ln.insert(node_id, succ);
1392+
self.break_ln.insert(expr.hir_id, succ);
13951393

13961394
let cond_ln = match kind {
13971395
LoopLoop => ln,
13981396
WhileLoop(ref cond) => self.propagate_through_expr(&cond, ln),
13991397
};
14001398

1401-
self.cont_ln.insert(node_id, cond_ln);
1399+
self.cont_ln.insert(expr.hir_id, cond_ln);
14021400

14031401
let body_ln = self.propagate_through_block(body, cond_ln);
14041402

src/librustc_mir/hair/cx/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
591591
match dest.target_id {
592592
Ok(target_id) => ExprKind::Break {
593593
label: region::Scope {
594-
id: cx.tcx.hir().node_to_hir_id(target_id).local_id,
594+
id: target_id.local_id,
595595
data: region::ScopeData::Node
596596
},
597597
value: value.to_ref(),
@@ -603,7 +603,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
603603
match dest.target_id {
604604
Ok(loop_id) => ExprKind::Continue {
605605
label: region::Scope {
606-
id: cx.tcx.hir().node_to_hir_id(loop_id).local_id,
606+
id: loop_id.local_id,
607607
data: region::ScopeData::Node
608608
},
609609
},

src/librustc_passes/loops.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc::hir::def_id::DefId;
88
use rustc::hir::map::Map;
99
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
1010
use rustc::hir::{self, Node, Destination};
11-
use syntax::ast;
1211
use syntax::struct_span_err;
1312
use syntax_pos::Span;
1413
use errors::Applicability;
@@ -105,25 +104,25 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
105104

106105
let loop_id = match label.target_id.into() {
107106
Ok(loop_id) => loop_id,
108-
Err(hir::LoopIdError::OutsideLoopScope) => ast::DUMMY_NODE_ID,
107+
Err(hir::LoopIdError::OutsideLoopScope) => hir::DUMMY_HIR_ID,
109108
Err(hir::LoopIdError::UnlabeledCfInWhileCondition) => {
110109
self.emit_unlabled_cf_in_while_condition(e.span, "break");
111-
ast::DUMMY_NODE_ID
110+
hir::DUMMY_HIR_ID
112111
},
113-
Err(hir::LoopIdError::UnresolvedLabel) => ast::DUMMY_NODE_ID,
112+
Err(hir::LoopIdError::UnresolvedLabel) => hir::DUMMY_HIR_ID,
114113
};
115114

116-
if loop_id != ast::DUMMY_NODE_ID {
117-
if let Node::Block(_) = self.hir_map.find(loop_id).unwrap() {
115+
if loop_id != hir::DUMMY_HIR_ID {
116+
if let Node::Block(_) = self.hir_map.find_by_hir_id(loop_id).unwrap() {
118117
return
119118
}
120119
}
121120

122121
if opt_expr.is_some() {
123-
let loop_kind = if loop_id == ast::DUMMY_NODE_ID {
122+
let loop_kind = if loop_id == hir::DUMMY_HIR_ID {
124123
None
125124
} else {
126-
Some(match self.hir_map.expect_expr(loop_id).node {
125+
Some(match self.hir_map.expect_expr_by_hir_id(loop_id).node {
127126
hir::ExprKind::While(..) => LoopKind::WhileLoop,
128127
hir::ExprKind::Loop(_, _, source) => LoopKind::Loop(source),
129128
ref r => span_bug!(e.span,
@@ -162,7 +161,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
162161

163162
match destination.target_id {
164163
Ok(loop_id) => {
165-
if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() {
164+
if let Node::Block(block) = self.hir_map.find_by_hir_id(loop_id).unwrap() {
166165
struct_span_err!(self.sess, e.span, E0696,
167166
"`continue` pointing to a labeled block")
168167
.span_label(e.span,

src/librustc_typeck/check/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4262,7 +4262,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
42624262
}
42634263
ExprKind::Break(destination, ref expr_opt) => {
42644264
if let Ok(target_id) = destination.target_id {
4265-
let target_id = tcx.hir().node_to_hir_id(target_id);
42664265
let (e_ty, cause);
42674266
if let Some(ref e) = *expr_opt {
42684267
// If this is a break with a value, we need to type-check

0 commit comments

Comments
 (0)