Skip to content

Commit

Permalink
rustc: use hir::ItemLocalId instead of ast::NodeId in CodeExtent.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Sep 1, 2017
1 parent ea6aca7 commit e4996ec
Show file tree
Hide file tree
Showing 37 changed files with 333 additions and 403 deletions.
10 changes: 6 additions & 4 deletions src/librustc/cfg/construct.rs
Expand Up @@ -582,10 +582,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
target_scope: CodeExtent,
to_index: CFGIndex) {
let mut data = CFGEdgeData { exiting_scopes: vec![] };
let mut scope = CodeExtent::Misc(from_expr.id);
let mut scope = CodeExtent::Misc(from_expr.hir_id.local_id);
let region_maps = self.tcx.region_maps(self.owner_def_id);
while scope != target_scope {
data.exiting_scopes.push(self.tcx.hir.node_to_hir_id(scope.node_id()).local_id);
data.exiting_scopes.push(scope.item_local_id());
scope = region_maps.encl_scope(scope);
}
self.graph.add_edge(from_index, to_index, data);
Expand All @@ -612,7 +612,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
hir::ScopeTarget::Block(block_expr_id) => {
for b in &self.breakable_block_scopes {
if b.block_expr_id == self.tcx.hir.node_to_hir_id(block_expr_id).local_id {
return (CodeExtent::Misc(block_expr_id), match scope_cf_kind {
let scope_id = self.tcx.hir.node_to_hir_id(block_expr_id).local_id;
return (CodeExtent::Misc(scope_id), match scope_cf_kind {
ScopeCfKind::Break => b.break_index,
ScopeCfKind::Continue => bug!("can't continue to block"),
});
Expand All @@ -623,7 +624,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
hir::ScopeTarget::Loop(hir::LoopIdResult::Ok(loop_id)) => {
for l in &self.loop_scopes {
if l.loop_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
return (CodeExtent::Misc(loop_id), match scope_cf_kind {
let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id;
return (CodeExtent::Misc(scope_id), match scope_cf_kind {
ScopeCfKind::Break => l.break_index,
ScopeCfKind::Continue => l.continue_index,
});
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/cfg/graphviz.rs
Expand Up @@ -32,8 +32,9 @@ pub struct LabelledCFG<'a, 'tcx: 'a> {

impl<'a, 'tcx> LabelledCFG<'a, 'tcx> {
fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String {
assert!(self.cfg.owner_def_id.is_local());
let node_id = self.tcx.hir.hir_to_node_id(hir::HirId {
owner: self.tcx.closure_base_def_id(self.cfg.owner_def_id).index,
owner: self.tcx.hir.def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
local_id
});
let s = self.tcx.hir.node_to_string(node_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Expand Up @@ -132,7 +132,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
prefix, scope, suffix)
};
let span = scope.span(self, region_maps);
let tag = match self.hir.find(scope.node_id()) {
let tag = match self.hir.find(scope.node_id(self, region_maps)) {
Some(hir_map::NodeBlock(_)) => "block",
Some(hir_map::NodeExpr(expr)) => match expr.node {
hir::ExprCall(..) => "call",
Expand Down
12 changes: 7 additions & 5 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -23,7 +23,7 @@ use hir::def::Def;
use hir::def_id::{DefId};
use infer::InferCtxt;
use middle::mem_categorization as mc;
use middle::region::RegionMaps;
use middle::region::{CodeExtent, RegionMaps};
use ty::{self, TyCtxt, adjustment};

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

let fn_body_scope_r = self.tcx().node_scope_region(body.value.id);
let fn_body_scope_r =
self.tcx().mk_region(ty::ReScope(CodeExtent::Misc(body.value.hir_id.local_id)));
let arg_cmt = self.mc.cat_rvalue(
arg.id,
arg.pat.span,
Expand Down Expand Up @@ -542,16 +543,17 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
ty::TyError => { }
_ => {
let def_id = self.mc.tables.type_dependent_defs()[call.hir_id].def_id();
let call_scope = CodeExtent::Misc(call.hir_id.local_id);
match OverloadedCallType::from_method_id(self.tcx(), def_id) {
FnMutOverloadedCall => {
let call_scope_r = self.tcx().node_scope_region(call.id);
let call_scope_r = self.tcx().mk_region(ty::ReScope(call_scope));
self.borrow_expr(callee,
call_scope_r,
ty::MutBorrow,
ClosureInvocation);
}
FnOverloadedCall => {
let call_scope_r = self.tcx().node_scope_region(call.id);
let call_scope_r = self.tcx().mk_region(ty::ReScope(call_scope));
self.borrow_expr(callee,
call_scope_r,
ty::ImmBorrow,
Expand Down Expand Up @@ -749,7 +751,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
// Converting from a &T to *T (or &mut T to *mut T) is
// treated as borrowing it for the enclosing temporary
// scope.
let r = self.tcx().node_scope_region(expr.id);
let r = self.tcx().mk_region(ty::ReScope(CodeExtent::Misc(expr.hir_id.local_id)));

self.delegate.borrow(expr.id,
expr.span,
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -861,8 +861,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {

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

0 comments on commit e4996ec

Please sign in to comment.