Skip to content

Commit e4996ec

Browse files
committed
rustc: use hir::ItemLocalId instead of ast::NodeId in CodeExtent.
1 parent ea6aca7 commit e4996ec

37 files changed

+333
-403
lines changed

src/librustc/cfg/construct.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
582582
target_scope: CodeExtent,
583583
to_index: CFGIndex) {
584584
let mut data = CFGEdgeData { exiting_scopes: vec![] };
585-
let mut scope = CodeExtent::Misc(from_expr.id);
585+
let mut scope = CodeExtent::Misc(from_expr.hir_id.local_id);
586586
let region_maps = self.tcx.region_maps(self.owner_def_id);
587587
while scope != target_scope {
588-
data.exiting_scopes.push(self.tcx.hir.node_to_hir_id(scope.node_id()).local_id);
588+
data.exiting_scopes.push(scope.item_local_id());
589589
scope = region_maps.encl_scope(scope);
590590
}
591591
self.graph.add_edge(from_index, to_index, data);
@@ -612,7 +612,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
612612
hir::ScopeTarget::Block(block_expr_id) => {
613613
for b in &self.breakable_block_scopes {
614614
if b.block_expr_id == self.tcx.hir.node_to_hir_id(block_expr_id).local_id {
615-
return (CodeExtent::Misc(block_expr_id), match scope_cf_kind {
615+
let scope_id = self.tcx.hir.node_to_hir_id(block_expr_id).local_id;
616+
return (CodeExtent::Misc(scope_id), match scope_cf_kind {
616617
ScopeCfKind::Break => b.break_index,
617618
ScopeCfKind::Continue => bug!("can't continue to block"),
618619
});
@@ -623,7 +624,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
623624
hir::ScopeTarget::Loop(hir::LoopIdResult::Ok(loop_id)) => {
624625
for l in &self.loop_scopes {
625626
if l.loop_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
626-
return (CodeExtent::Misc(loop_id), match scope_cf_kind {
627+
let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id;
628+
return (CodeExtent::Misc(scope_id), match scope_cf_kind {
627629
ScopeCfKind::Break => l.break_index,
628630
ScopeCfKind::Continue => l.continue_index,
629631
});

src/librustc/cfg/graphviz.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ pub struct LabelledCFG<'a, 'tcx: 'a> {
3232

3333
impl<'a, 'tcx> LabelledCFG<'a, 'tcx> {
3434
fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String {
35+
assert!(self.cfg.owner_def_id.is_local());
3536
let node_id = self.tcx.hir.hir_to_node_id(hir::HirId {
36-
owner: self.tcx.closure_base_def_id(self.cfg.owner_def_id).index,
37+
owner: self.tcx.hir.def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
3738
local_id
3839
});
3940
let s = self.tcx.hir.node_to_string(node_id);

src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
132132
prefix, scope, suffix)
133133
};
134134
let span = scope.span(self, region_maps);
135-
let tag = match self.hir.find(scope.node_id()) {
135+
let tag = match self.hir.find(scope.node_id(self, region_maps)) {
136136
Some(hir_map::NodeBlock(_)) => "block",
137137
Some(hir_map::NodeExpr(expr)) => match expr.node {
138138
hir::ExprCall(..) => "call",

src/librustc/middle/expr_use_visitor.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use hir::def::Def;
2323
use hir::def_id::{DefId};
2424
use infer::InferCtxt;
2525
use middle::mem_categorization as mc;
26-
use middle::region::RegionMaps;
26+
use middle::region::{CodeExtent, RegionMaps};
2727
use ty::{self, TyCtxt, adjustment};
2828

2929
use hir::{self, PatKind};
@@ -298,7 +298,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
298298
for arg in &body.arguments {
299299
let arg_ty = return_if_err!(self.mc.node_ty(arg.pat.hir_id));
300300

301-
let fn_body_scope_r = self.tcx().node_scope_region(body.value.id);
301+
let fn_body_scope_r =
302+
self.tcx().mk_region(ty::ReScope(CodeExtent::Misc(body.value.hir_id.local_id)));
302303
let arg_cmt = self.mc.cat_rvalue(
303304
arg.id,
304305
arg.pat.span,
@@ -542,16 +543,17 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
542543
ty::TyError => { }
543544
_ => {
544545
let def_id = self.mc.tables.type_dependent_defs()[call.hir_id].def_id();
546+
let call_scope = CodeExtent::Misc(call.hir_id.local_id);
545547
match OverloadedCallType::from_method_id(self.tcx(), def_id) {
546548
FnMutOverloadedCall => {
547-
let call_scope_r = self.tcx().node_scope_region(call.id);
549+
let call_scope_r = self.tcx().mk_region(ty::ReScope(call_scope));
548550
self.borrow_expr(callee,
549551
call_scope_r,
550552
ty::MutBorrow,
551553
ClosureInvocation);
552554
}
553555
FnOverloadedCall => {
554-
let call_scope_r = self.tcx().node_scope_region(call.id);
556+
let call_scope_r = self.tcx().mk_region(ty::ReScope(call_scope));
555557
self.borrow_expr(callee,
556558
call_scope_r,
557559
ty::ImmBorrow,
@@ -749,7 +751,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
749751
// Converting from a &T to *T (or &mut T to *mut T) is
750752
// treated as borrowing it for the enclosing temporary
751753
// scope.
752-
let r = self.tcx().node_scope_region(expr.id);
754+
let r = self.tcx().mk_region(ty::ReScope(CodeExtent::Misc(expr.hir_id.local_id)));
753755

754756
self.delegate.borrow(expr.id,
755757
expr.span,

src/librustc/middle/mem_categorization.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
861861

862862
/// Returns the lifetime of a temporary created by expr with id `id`.
863863
/// This could be `'static` if `id` is part of a constant expression.
864-
pub fn temporary_scope(&self, id: ast::NodeId) -> ty::Region<'tcx>
865-
{
864+
pub fn temporary_scope(&self, id: hir::ItemLocalId) -> ty::Region<'tcx> {
866865
let scope = self.region_maps.temporary_scope(id);
867866
self.tcx.mk_region(match scope {
868867
Some(scope) => ty::ReScope(scope),
@@ -890,7 +889,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
890889
let re = if promotable {
891890
self.tcx.types.re_static
892891
} else {
893-
self.temporary_scope(id)
892+
self.temporary_scope(self.tcx.hir.node_to_hir_id(id).local_id)
894893
};
895894
let ret = self.cat_rvalue(id, span, re, expr_ty);
896895
debug!("cat_rvalue_node ret {:?}", ret);

0 commit comments

Comments
 (0)