Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
hir: replace NodeId with HirId in Destination
  • Loading branch information
ljedrz committed Mar 7, 2019
1 parent 558a07b commit 42fbcb5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/librustc/cfg/construct.rs
Expand Up @@ -571,9 +571,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
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 {
Expand All @@ -583,9 +583,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}
}
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 {
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/hir/intravisit.rs
Expand Up @@ -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) => {
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/hir/lowering.rs
Expand Up @@ -1068,7 +1068,7 @@ impl<'a> LoweringContext<'a> {
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)
}
Expand All @@ -1077,7 +1077,7 @@ impl<'a> LoweringContext<'a> {
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()
}
Expand Down Expand Up @@ -4564,12 +4564,13 @@ impl<'a> LoweringContext<'a> {
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),
),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Expand Up @@ -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)]
Expand Down
16 changes: 7 additions & 9 deletions src/librustc/middle/liveness.rs
Expand Up @@ -102,7 +102,7 @@ use crate::hir::Node;
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};
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -951,8 +951,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
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| {
Expand Down Expand Up @@ -1111,7 +1110,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
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();

Expand Down Expand Up @@ -1390,15 +1389,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
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);

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -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(),
Expand All @@ -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
},
},
Expand Down
17 changes: 8 additions & 9 deletions src/librustc_passes/loops.rs
Expand Up @@ -8,7 +8,6 @@ use rustc::hir::def_id::DefId;
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;
Expand Down Expand Up @@ -105,25 +104,25 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {

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,
Expand Down Expand Up @@ -162,7 +161,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {

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,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_typeck/check/mod.rs
Expand Up @@ -4262,7 +4262,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
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
Expand Down

0 comments on commit 42fbcb5

Please sign in to comment.