hir: replace NodeId with HirId in Destination
This commit is contained in:
parent
558a07b896
commit
42fbcb567c
8 changed files with 30 additions and 29 deletions
|
@ -571,9 +571,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||||
match destination.target_id {
|
match destination.target_id {
|
||||||
Ok(loop_id) => {
|
Ok(loop_id) => {
|
||||||
for b in &self.breakable_block_scopes {
|
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 {
|
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
|
data: region::ScopeData::Node
|
||||||
};
|
};
|
||||||
return (scope, match scope_cf_kind {
|
return (scope, match scope_cf_kind {
|
||||||
|
@ -583,9 +583,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for l in &self.loop_scopes {
|
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 {
|
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
|
data: region::ScopeData::Node
|
||||||
};
|
};
|
||||||
return (scope, match scope_cf_kind {
|
return (scope, match scope_cf_kind {
|
||||||
|
|
|
@ -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) => {
|
ExprKind::Break(ref destination, ref opt_expr) => {
|
||||||
if let Some(ref label) = destination.label {
|
if let Some(ref label) = destination.label {
|
||||||
visitor.visit_label(label);
|
visitor.visit_label(label);
|
||||||
|
/*
|
||||||
if let Ok(node_id) = destination.target_id {
|
if let Ok(node_id) = destination.target_id {
|
||||||
visitor.visit_def_mention(Def::Label(node_id))
|
visitor.visit_def_mention(Def::Label(node_id))
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
walk_list!(visitor, visit_expr, opt_expr);
|
walk_list!(visitor, visit_expr, opt_expr);
|
||||||
}
|
}
|
||||||
ExprKind::Continue(ref destination) => {
|
ExprKind::Continue(ref destination) => {
|
||||||
if let Some(ref label) = destination.label {
|
if let Some(ref label) = destination.label {
|
||||||
visitor.visit_label(label);
|
visitor.visit_label(label);
|
||||||
|
/*
|
||||||
if let Ok(node_id) = destination.target_id {
|
if let Ok(node_id) = destination.target_id {
|
||||||
visitor.visit_def_mention(Def::Label(node_id))
|
visitor.visit_def_mention(Def::Label(node_id))
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Ret(ref optional_expression) => {
|
ExprKind::Ret(ref optional_expression) => {
|
||||||
|
|
|
@ -1068,7 +1068,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
let target_id = match destination {
|
let target_id = match destination {
|
||||||
Some((id, _)) => {
|
Some((id, _)) => {
|
||||||
if let Def::Label(loop_id) = self.expect_full_def(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 {
|
} else {
|
||||||
Err(hir::LoopIdError::UnresolvedLabel)
|
Err(hir::LoopIdError::UnresolvedLabel)
|
||||||
}
|
}
|
||||||
|
@ -1077,7 +1077,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
self.loop_scopes
|
self.loop_scopes
|
||||||
.last()
|
.last()
|
||||||
.cloned()
|
.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))
|
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope))
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
@ -4564,12 +4564,13 @@ impl<'a> LoweringContext<'a> {
|
||||||
let thin_attrs = ThinVec::from(attrs);
|
let thin_attrs = ThinVec::from(attrs);
|
||||||
let catch_scope = self.catch_scopes.last().map(|x| *x);
|
let catch_scope = self.catch_scopes.last().map(|x| *x);
|
||||||
let ret_expr = if let Some(catch_node) = catch_scope {
|
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(
|
P(self.expr(
|
||||||
e.span,
|
e.span,
|
||||||
hir::ExprKind::Break(
|
hir::ExprKind::Break(
|
||||||
hir::Destination {
|
hir::Destination {
|
||||||
label: None,
|
label: None,
|
||||||
target_id: Ok(catch_node),
|
target_id,
|
||||||
},
|
},
|
||||||
Some(from_err_expr),
|
Some(from_err_expr),
|
||||||
),
|
),
|
||||||
|
|
|
@ -1618,7 +1618,7 @@ pub struct Destination {
|
||||||
|
|
||||||
// These errors are caught and then reported during the diagnostics pass in
|
// These errors are caught and then reported during the diagnostics pass in
|
||||||
// librustc_passes/loops.rs
|
// 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)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||||
|
|
|
@ -102,7 +102,7 @@ use crate::hir::Node;
|
||||||
use crate::ty::{self, TyCtxt};
|
use crate::ty::{self, TyCtxt};
|
||||||
use crate::ty::query::Providers;
|
use crate::ty::query::Providers;
|
||||||
use crate::lint;
|
use crate::lint;
|
||||||
use crate::util::nodemap::{NodeMap, HirIdMap, HirIdSet};
|
use crate::util::nodemap::{HirIdMap, HirIdSet};
|
||||||
|
|
||||||
use errors::Applicability;
|
use errors::Applicability;
|
||||||
use std::collections::{BTreeMap, VecDeque};
|
use std::collections::{BTreeMap, VecDeque};
|
||||||
|
@ -669,8 +669,8 @@ struct Liveness<'a, 'tcx: 'a> {
|
||||||
// mappings from loop node ID to LiveNode
|
// mappings from loop node ID to LiveNode
|
||||||
// ("break" label should map to loop node ID,
|
// ("break" label should map to loop node ID,
|
||||||
// it probably doesn't now)
|
// it probably doesn't now)
|
||||||
break_ln: NodeMap<LiveNode>,
|
break_ln: HirIdMap<LiveNode>,
|
||||||
cont_ln: NodeMap<LiveNode>,
|
cont_ln: HirIdMap<LiveNode>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
|
@ -951,8 +951,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode)
|
fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode)
|
||||||
-> LiveNode {
|
-> LiveNode {
|
||||||
if blk.targeted_by_break {
|
if blk.targeted_by_break {
|
||||||
let node_id = self.ir.tcx.hir().hir_to_node_id(blk.hir_id);
|
self.break_ln.insert(blk.hir_id, succ);
|
||||||
self.break_ln.insert(node_id, succ);
|
|
||||||
}
|
}
|
||||||
let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
|
let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
|
||||||
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
|
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
|
||||||
|
@ -1111,7 +1110,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
hir::ExprKind::Break(label, ref opt_expr) => {
|
hir::ExprKind::Break(label, ref opt_expr) => {
|
||||||
// Find which label this break jumps to
|
// Find which label this break jumps to
|
||||||
let target = match label.target_id {
|
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),
|
Err(err) => span_bug!(expr.span, "loop scope error: {}", err),
|
||||||
}.cloned();
|
}.cloned();
|
||||||
|
|
||||||
|
@ -1390,15 +1389,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||||
debug!("propagate_through_loop: using id for loop body {} {}",
|
debug!("propagate_through_loop: using id for loop body {} {}",
|
||||||
expr.hir_id, self.ir.tcx.hir().hir_to_pretty_string(body.hir_id));
|
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(expr.hir_id, succ);
|
||||||
self.break_ln.insert(node_id, succ);
|
|
||||||
|
|
||||||
let cond_ln = match kind {
|
let cond_ln = match kind {
|
||||||
LoopLoop => ln,
|
LoopLoop => ln,
|
||||||
WhileLoop(ref cond) => self.propagate_through_expr(&cond, 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);
|
let body_ln = self.propagate_through_block(body, cond_ln);
|
||||||
|
|
||||||
|
|
|
@ -591,7 +591,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
||||||
match dest.target_id {
|
match dest.target_id {
|
||||||
Ok(target_id) => ExprKind::Break {
|
Ok(target_id) => ExprKind::Break {
|
||||||
label: region::Scope {
|
label: region::Scope {
|
||||||
id: cx.tcx.hir().node_to_hir_id(target_id).local_id,
|
id: target_id.local_id,
|
||||||
data: region::ScopeData::Node
|
data: region::ScopeData::Node
|
||||||
},
|
},
|
||||||
value: value.to_ref(),
|
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 {
|
match dest.target_id {
|
||||||
Ok(loop_id) => ExprKind::Continue {
|
Ok(loop_id) => ExprKind::Continue {
|
||||||
label: region::Scope {
|
label: region::Scope {
|
||||||
id: cx.tcx.hir().node_to_hir_id(loop_id).local_id,
|
id: loop_id.local_id,
|
||||||
data: region::ScopeData::Node
|
data: region::ScopeData::Node
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,7 +8,6 @@ use rustc::hir::def_id::DefId;
|
||||||
use rustc::hir::map::Map;
|
use rustc::hir::map::Map;
|
||||||
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||||
use rustc::hir::{self, Node, Destination};
|
use rustc::hir::{self, Node, Destination};
|
||||||
use syntax::ast;
|
|
||||||
use syntax::struct_span_err;
|
use syntax::struct_span_err;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use errors::Applicability;
|
use errors::Applicability;
|
||||||
|
@ -105,25 +104,25 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
|
||||||
|
|
||||||
let loop_id = match label.target_id.into() {
|
let loop_id = match label.target_id.into() {
|
||||||
Ok(loop_id) => loop_id,
|
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) => {
|
Err(hir::LoopIdError::UnlabeledCfInWhileCondition) => {
|
||||||
self.emit_unlabled_cf_in_while_condition(e.span, "break");
|
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 loop_id != hir::DUMMY_HIR_ID {
|
||||||
if let Node::Block(_) = self.hir_map.find(loop_id).unwrap() {
|
if let Node::Block(_) = self.hir_map.find_by_hir_id(loop_id).unwrap() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt_expr.is_some() {
|
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
|
None
|
||||||
} else {
|
} 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::While(..) => LoopKind::WhileLoop,
|
||||||
hir::ExprKind::Loop(_, _, source) => LoopKind::Loop(source),
|
hir::ExprKind::Loop(_, _, source) => LoopKind::Loop(source),
|
||||||
ref r => span_bug!(e.span,
|
ref r => span_bug!(e.span,
|
||||||
|
@ -162,7 +161,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
|
||||||
|
|
||||||
match destination.target_id {
|
match destination.target_id {
|
||||||
Ok(loop_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,
|
struct_span_err!(self.sess, e.span, E0696,
|
||||||
"`continue` pointing to a labeled block")
|
"`continue` pointing to a labeled block")
|
||||||
.span_label(e.span,
|
.span_label(e.span,
|
||||||
|
|
|
@ -4262,7 +4262,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
ExprKind::Break(destination, ref expr_opt) => {
|
ExprKind::Break(destination, ref expr_opt) => {
|
||||||
if let Ok(target_id) = destination.target_id {
|
if let Ok(target_id) = destination.target_id {
|
||||||
let target_id = tcx.hir().node_to_hir_id(target_id);
|
|
||||||
let (e_ty, cause);
|
let (e_ty, cause);
|
||||||
if let Some(ref e) = *expr_opt {
|
if let Some(ref e) = *expr_opt {
|
||||||
// If this is a break with a value, we need to type-check
|
// If this is a break with a value, we need to type-check
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue