Skip to content

Commit 6c2f64b

Browse files
committed
modify ExprUseVisitor and friends to take region-maps, not def-id
1 parent 73cd9bd commit 6c2f64b

File tree

8 files changed

+30
-27
lines changed

8 files changed

+30
-27
lines changed

src/librustc/middle/expr_use_visitor.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +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;
2627
use ty::{self, TyCtxt, adjustment};
2728

2829
use hir::{self, PatKind};
@@ -270,24 +271,24 @@ enum PassArgs {
270271

271272
impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
272273
pub fn new(delegate: &'a mut (Delegate<'tcx>+'a),
273-
context: DefId,
274+
region_maps: &'a RegionMaps<'tcx>,
274275
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>)
275276
-> Self
276277
{
277278
ExprUseVisitor::with_options(delegate,
278279
infcx,
279-
context,
280+
region_maps,
280281
mc::MemCategorizationOptions::default())
281282
}
282283

283284
pub fn with_options(delegate: &'a mut (Delegate<'tcx>+'a),
284285
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
285-
context: DefId,
286+
region_maps: &'a RegionMaps<'tcx>,
286287
options: mc::MemCategorizationOptions)
287288
-> Self
288289
{
289290
ExprUseVisitor {
290-
mc: mc::MemCategorizationContext::with_options(infcx, context, options),
291+
mc: mc::MemCategorizationContext::with_options(infcx, region_maps, options),
291292
delegate: delegate
292293
}
293294
}

src/librustc/middle/mem_categorization.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl ast_node for hir::Pat {
290290
#[derive(Clone)]
291291
pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
292292
pub infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
293-
pub region_maps: Rc<RegionMaps<'tcx>>,
293+
pub region_maps: &'a RegionMaps<'tcx>,
294294
options: MemCategorizationOptions,
295295
}
296296

@@ -406,16 +406,15 @@ impl MutabilityCategory {
406406
impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
407407
/// Context should be the `DefId` we use to fetch region-maps.
408408
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
409-
context: DefId)
409+
region_maps: &'a RegionMaps<'tcx>)
410410
-> MemCategorizationContext<'a, 'gcx, 'tcx> {
411-
MemCategorizationContext::with_options(infcx, context, MemCategorizationOptions::default())
411+
MemCategorizationContext::with_options(infcx, region_maps, MemCategorizationOptions::default())
412412
}
413413

414414
pub fn with_options(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
415-
context: DefId,
415+
region_maps: &'a RegionMaps<'tcx>,
416416
options: MemCategorizationOptions)
417417
-> MemCategorizationContext<'a, 'gcx, 'tcx> {
418-
let region_maps = infcx.tcx.region_maps(context);
419418
MemCategorizationContext {
420419
infcx: infcx,
421420
region_maps: region_maps,

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
199199
all_loans: all_loans,
200200
param_env: &infcx.parameter_environment
201201
};
202-
euv::ExprUseVisitor::new(&mut clcx, bccx.owner_def_id, &infcx).consume_body(body);
202+
euv::ExprUseVisitor::new(&mut clcx, &bccx.region_maps, &infcx).consume_body(body);
203203
}
204204

205205
#[derive(PartialEq)]

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
5151
};
5252

5353
let body = glcx.bccx.tcx.hir.body(body);
54-
euv::ExprUseVisitor::new(&mut glcx, bccx.owner_def_id, &infcx).consume_body(body);
54+
euv::ExprUseVisitor::new(&mut glcx, &bccx.region_maps, &infcx).consume_body(body);
5555

5656
glcx.report_potential_errors();
5757
let GatherLoanCtxt { all_loans, move_data, .. } = glcx;

src/librustc_const_eval/check_match.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use _match::WitnessPreference::*;
1414

1515
use pattern::{Pattern, PatternContext, PatternError, PatternKind};
1616

17-
use rustc::hir::def_id::DefId;
1817
use rustc::middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor};
1918
use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
2019
use rustc::middle::expr_use_visitor as euv;
2120
use rustc::middle::mem_categorization::{cmt};
21+
use rustc::middle::region::RegionMaps;
2222
use rustc::session::Session;
2323
use rustc::traits::Reveal;
2424
use rustc::ty::{self, Ty, TyCtxt};
@@ -47,11 +47,12 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
4747
intravisit::walk_fn(self, fk, fd, b, s, id);
4848

4949
let region_context = self.tcx.hir.local_def_id(id);
50+
let region_maps = self.tcx.region_maps(region_context);
5051

5152
MatchVisitor {
5253
tcx: self.tcx,
5354
tables: self.tcx.body_tables(b),
54-
region_context: region_context,
55+
region_maps: &region_maps,
5556
param_env: &ty::ParameterEnvironment::for_item(self.tcx, id)
5657
}.visit_body(self.tcx.hir.body(b));
5758
}
@@ -68,9 +69,9 @@ fn create_e0004<'a>(sess: &'a Session, sp: Span, error_message: String) -> Diagn
6869

6970
struct MatchVisitor<'a, 'tcx: 'a> {
7071
tcx: TyCtxt<'a, 'tcx, 'tcx>,
71-
region_context: DefId,
7272
tables: &'a ty::TypeckTables<'tcx>,
73-
param_env: &'a ty::ParameterEnvironment<'tcx>
73+
param_env: &'a ty::ParameterEnvironment<'tcx>,
74+
region_maps: &'a RegionMaps<'tcx>,
7475
}
7576

7677
impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> {
@@ -522,7 +523,7 @@ fn check_for_mutation_in_guard(cx: &MatchVisitor, guard: &hir::Expr) {
522523
let mut checker = MutationChecker {
523524
cx: cx,
524525
};
525-
ExprUseVisitor::new(&mut checker, cx.region_context, &infcx).walk_expr(guard);
526+
ExprUseVisitor::new(&mut checker, cx.region_maps, &infcx).walk_expr(guard);
526527
});
527528
}
528529

src/librustc_passes/consts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
141141
let outer_penv = self.tcx.infer_ctxt(body_id, Reveal::UserFacing).enter(|infcx| {
142142
let param_env = infcx.parameter_environment.clone();
143143
let outer_penv = mem::replace(&mut self.param_env, param_env);
144-
euv::ExprUseVisitor::new(self, item_def_id, &infcx).consume_body(body);
144+
let region_maps = &self.tcx.region_maps(item_def_id);;
145+
euv::ExprUseVisitor::new(self, region_maps, &infcx).consume_body(body);
145146
outer_penv
146147
});
147148

src/librustc_typeck/check/regionck.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> {
577577
// If necessary, constrain destructors in the unadjusted form of this
578578
// expression.
579579
let cmt_result = {
580-
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
580+
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
581581
mc.cat_expr_unadjusted(expr)
582582
};
583583
match cmt_result {
@@ -594,7 +594,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> {
594594
// If necessary, constrain destructors in this expression. This will be
595595
// the adjusted form if there is an adjustment.
596596
let cmt_result = {
597-
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
597+
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
598598
mc.cat_expr(expr)
599599
};
600600
match cmt_result {
@@ -956,7 +956,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
956956
r, m);
957957

958958
{
959-
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
959+
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
960960
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
961961
debug!("constrain_autoderefs: self_cmt={:?}",
962962
self_cmt);
@@ -1068,7 +1068,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
10681068
debug!("link_addr_of(expr={:?}, base={:?})", expr, base);
10691069

10701070
let cmt = {
1071-
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
1071+
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
10721072
ignore_err!(mc.cat_expr(base))
10731073
};
10741074

@@ -1086,7 +1086,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
10861086
None => { return; }
10871087
Some(ref expr) => &**expr,
10881088
};
1089-
let mc = &mc::MemCategorizationContext::new(self, self.subject_def_id);
1089+
let mc = &mc::MemCategorizationContext::new(self, &self.region_maps);
10901090
let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
10911091
self.link_pattern(mc, discr_cmt, &local.pat);
10921092
}
@@ -1096,7 +1096,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
10961096
/// linked to the lifetime of its guarantor (if any).
10971097
fn link_match(&self, discr: &hir::Expr, arms: &[hir::Arm]) {
10981098
debug!("regionck::for_match()");
1099-
let mc = &mc::MemCategorizationContext::new(self, self.subject_def_id);
1099+
let mc = &mc::MemCategorizationContext::new(self, &self.region_maps);
11001100
let discr_cmt = ignore_err!(mc.cat_expr(discr));
11011101
debug!("discr_cmt={:?}", discr_cmt);
11021102
for arm in arms {
@@ -1111,7 +1111,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
11111111
/// linked to the lifetime of its guarantor (if any).
11121112
fn link_fn_args(&self, body_scope: CodeExtent<'tcx>, args: &[hir::Arg]) {
11131113
debug!("regionck::link_fn_args(body_scope={:?})", body_scope);
1114-
let mc = &mc::MemCategorizationContext::new(self, self.subject_def_id);
1114+
let mc = &mc::MemCategorizationContext::new(self, &self.region_maps);
11151115
for arg in args {
11161116
let arg_ty = self.node_ty(arg.id);
11171117
let re_scope = self.tcx.mk_region(ty::ReScope(body_scope));
@@ -1154,7 +1154,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
11541154
autoref: &adjustment::AutoBorrow<'tcx>)
11551155
{
11561156
debug!("link_autoref(autoderefs={}, autoref={:?})", autoderefs, autoref);
1157-
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
1157+
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
11581158
let expr_cmt = ignore_err!(mc.cat_expr_autoderefd(expr, autoderefs));
11591159
debug!("expr_cmt={:?}", expr_cmt);
11601160

@@ -1178,7 +1178,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
11781178
callee_scope: CodeExtent<'tcx>) {
11791179
debug!("link_by_ref(expr={:?}, callee_scope={:?})",
11801180
expr, callee_scope);
1181-
let mc = mc::MemCategorizationContext::new(self, self.subject_def_id);
1181+
let mc = mc::MemCategorizationContext::new(self, &self.region_maps);
11821182
let expr_cmt = ignore_err!(mc.cat_expr(expr));
11831183
let borrow_region = self.tcx.mk_region(ty::ReScope(callee_scope));
11841184
self.link_region(expr.span, borrow_region, ty::ImmBorrow, expr_cmt);

src/librustc_typeck/check/upvar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ impl<'a, 'gcx, 'tcx> AdjustBorrowKind<'a, 'gcx, 'tcx> {
165165

166166
{
167167
let body_owner_def_id = self.fcx.tcx.hir.body_owner_def_id(body.id());
168+
let region_maps = &self.fcx.tcx.region_maps(body_owner_def_id);
168169
let mut euv =
169170
euv::ExprUseVisitor::with_options(self,
170171
self.fcx,
171-
body_owner_def_id,
172+
region_maps,
172173
mc::MemCategorizationOptions {
173174
during_closure_kind_inference: true
174175
});

0 commit comments

Comments
 (0)