modify ExprUseVisitor and friends to take region-maps, not def-id

This commit is contained in:
Niko Matsakis 2017-04-29 07:05:03 -04:00
parent 73cd9bde37
commit 6c2f64bdd8
8 changed files with 30 additions and 27 deletions

View File

@ -23,6 +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 ty::{self, TyCtxt, adjustment};
use hir::{self, PatKind};
@ -270,24 +271,24 @@ enum PassArgs {
impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
pub fn new(delegate: &'a mut (Delegate<'tcx>+'a),
context: DefId,
region_maps: &'a RegionMaps<'tcx>,
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>)
-> Self
{
ExprUseVisitor::with_options(delegate,
infcx,
context,
region_maps,
mc::MemCategorizationOptions::default())
}
pub fn with_options(delegate: &'a mut (Delegate<'tcx>+'a),
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
context: DefId,
region_maps: &'a RegionMaps<'tcx>,
options: mc::MemCategorizationOptions)
-> Self
{
ExprUseVisitor {
mc: mc::MemCategorizationContext::with_options(infcx, context, options),
mc: mc::MemCategorizationContext::with_options(infcx, region_maps, options),
delegate: delegate
}
}

View File

@ -290,7 +290,7 @@ impl ast_node for hir::Pat {
#[derive(Clone)]
pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
pub infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
pub region_maps: Rc<RegionMaps<'tcx>>,
pub region_maps: &'a RegionMaps<'tcx>,
options: MemCategorizationOptions,
}
@ -406,16 +406,15 @@ impl MutabilityCategory {
impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
/// Context should be the `DefId` we use to fetch region-maps.
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
context: DefId)
region_maps: &'a RegionMaps<'tcx>)
-> MemCategorizationContext<'a, 'gcx, 'tcx> {
MemCategorizationContext::with_options(infcx, context, MemCategorizationOptions::default())
MemCategorizationContext::with_options(infcx, region_maps, MemCategorizationOptions::default())
}
pub fn with_options(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
context: DefId,
region_maps: &'a RegionMaps<'tcx>,
options: MemCategorizationOptions)
-> MemCategorizationContext<'a, 'gcx, 'tcx> {
let region_maps = infcx.tcx.region_maps(context);
MemCategorizationContext {
infcx: infcx,
region_maps: region_maps,

View File

@ -199,7 +199,7 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
all_loans: all_loans,
param_env: &infcx.parameter_environment
};
euv::ExprUseVisitor::new(&mut clcx, bccx.owner_def_id, &infcx).consume_body(body);
euv::ExprUseVisitor::new(&mut clcx, &bccx.region_maps, &infcx).consume_body(body);
}
#[derive(PartialEq)]

View File

@ -51,7 +51,7 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
};
let body = glcx.bccx.tcx.hir.body(body);
euv::ExprUseVisitor::new(&mut glcx, bccx.owner_def_id, &infcx).consume_body(body);
euv::ExprUseVisitor::new(&mut glcx, &bccx.region_maps, &infcx).consume_body(body);
glcx.report_potential_errors();
let GatherLoanCtxt { all_loans, move_data, .. } = glcx;

View File

@ -14,11 +14,11 @@ use _match::WitnessPreference::*;
use pattern::{Pattern, PatternContext, PatternError, PatternKind};
use rustc::hir::def_id::DefId;
use rustc::middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor};
use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization::{cmt};
use rustc::middle::region::RegionMaps;
use rustc::session::Session;
use rustc::traits::Reveal;
use rustc::ty::{self, Ty, TyCtxt};
@ -47,11 +47,12 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
intravisit::walk_fn(self, fk, fd, b, s, id);
let region_context = self.tcx.hir.local_def_id(id);
let region_maps = self.tcx.region_maps(region_context);
MatchVisitor {
tcx: self.tcx,
tables: self.tcx.body_tables(b),
region_context: region_context,
region_maps: &region_maps,
param_env: &ty::ParameterEnvironment::for_item(self.tcx, id)
}.visit_body(self.tcx.hir.body(b));
}
@ -68,9 +69,9 @@ fn create_e0004<'a>(sess: &'a Session, sp: Span, error_message: String) -> Diagn
struct MatchVisitor<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
region_context: DefId,
tables: &'a ty::TypeckTables<'tcx>,
param_env: &'a ty::ParameterEnvironment<'tcx>
param_env: &'a ty::ParameterEnvironment<'tcx>,
region_maps: &'a RegionMaps<'tcx>,
}
impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> {
@ -522,7 +523,7 @@ fn check_for_mutation_in_guard(cx: &MatchVisitor, guard: &hir::Expr) {
let mut checker = MutationChecker {
cx: cx,
};
ExprUseVisitor::new(&mut checker, cx.region_context, &infcx).walk_expr(guard);
ExprUseVisitor::new(&mut checker, cx.region_maps, &infcx).walk_expr(guard);
});
}

View File

@ -141,7 +141,8 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
let outer_penv = self.tcx.infer_ctxt(body_id, Reveal::UserFacing).enter(|infcx| {
let param_env = infcx.parameter_environment.clone();
let outer_penv = mem::replace(&mut self.param_env, param_env);
euv::ExprUseVisitor::new(self, item_def_id, &infcx).consume_body(body);
let region_maps = &self.tcx.region_maps(item_def_id);;
euv::ExprUseVisitor::new(self, region_maps, &infcx).consume_body(body);
outer_penv
});

View File

@ -577,7 +577,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> {
// If necessary, constrain destructors in the unadjusted form of this
// expression.
let cmt_result = {
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
mc.cat_expr_unadjusted(expr)
};
match cmt_result {
@ -594,7 +594,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> {
// If necessary, constrain destructors in this expression. This will be
// the adjusted form if there is an adjustment.
let cmt_result = {
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
mc.cat_expr(expr)
};
match cmt_result {
@ -956,7 +956,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
r, m);
{
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
debug!("constrain_autoderefs: self_cmt={:?}",
self_cmt);
@ -1068,7 +1068,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
debug!("link_addr_of(expr={:?}, base={:?})", expr, base);
let cmt = {
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
ignore_err!(mc.cat_expr(base))
};
@ -1086,7 +1086,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
None => { return; }
Some(ref expr) => &**expr,
};
let mc = &mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = &mc::MemCategorizationContext::new(self, &self.region_maps);
let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
self.link_pattern(mc, discr_cmt, &local.pat);
}
@ -1096,7 +1096,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
/// linked to the lifetime of its guarantor (if any).
fn link_match(&self, discr: &hir::Expr, arms: &[hir::Arm]) {
debug!("regionck::for_match()");
let mc = &mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = &mc::MemCategorizationContext::new(self, &self.region_maps);
let discr_cmt = ignore_err!(mc.cat_expr(discr));
debug!("discr_cmt={:?}", discr_cmt);
for arm in arms {
@ -1111,7 +1111,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
/// linked to the lifetime of its guarantor (if any).
fn link_fn_args(&self, body_scope: CodeExtent<'tcx>, args: &[hir::Arg]) {
debug!("regionck::link_fn_args(body_scope={:?})", body_scope);
let mc = &mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = &mc::MemCategorizationContext::new(self, &self.region_maps);
for arg in args {
let arg_ty = self.node_ty(arg.id);
let re_scope = self.tcx.mk_region(ty::ReScope(body_scope));
@ -1154,7 +1154,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
autoref: &adjustment::AutoBorrow<'tcx>)
{
debug!("link_autoref(autoderefs={}, autoref={:?})", autoderefs, autoref);
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
let expr_cmt = ignore_err!(mc.cat_expr_autoderefd(expr, autoderefs));
debug!("expr_cmt={:?}", expr_cmt);
@ -1178,7 +1178,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
callee_scope: CodeExtent<'tcx>) {
debug!("link_by_ref(expr={:?}, callee_scope={:?})",
expr, callee_scope);
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
let expr_cmt = ignore_err!(mc.cat_expr(expr));
let borrow_region = self.tcx.mk_region(ty::ReScope(callee_scope));
self.link_region(expr.span, borrow_region, ty::ImmBorrow, expr_cmt);

View File

@ -165,10 +165,11 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
{
let body_owner_def_id = self.fcx.tcx.hir.body_owner_def_id(body.id());
let region_maps = &self.fcx.tcx.region_maps(body_owner_def_id);
let mut euv =
euv::ExprUseVisitor::with_options(self,
self.fcx,
body_owner_def_id,
region_maps,
mc::MemCategorizationOptions {
during_closure_kind_inference: true
});