Skip to content

Commit f3ff084

Browse files
committed
Remove the regionck impl of Typer and just use fcx. This requires
modifying fcx to remove type variables where possible, but that's it.
1 parent 230d0eb commit f3ff084

File tree

2 files changed

+19
-55
lines changed

2 files changed

+19
-55
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,16 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> {
287287
self.ccx.tcx
288288
}
289289
fn node_ty(&self, id: ast::NodeId) -> McResult<Ty<'tcx>> {
290-
Ok(self.node_ty(id))
290+
let ty = self.node_ty(id);
291+
Ok(self.infcx().resolve_type_vars_if_possible(ty))
292+
}
291293
}
292294
fn node_method_ty(&self, method_call: ty::MethodCall)
293295
-> Option<Ty<'tcx>> {
294-
self.inh.method_map.borrow().get(&method_call).map(|m| m.ty)
296+
self.inh.method_map.borrow()
297+
.get(&method_call)
298+
.map(|method| method.ty)
299+
.map(|ty| self.infcx().resolve_type_vars_if_possible(ty))
295300
}
296301
fn adjustments(&self) -> &RefCell<NodeMap<ty::AutoAdjustment<'tcx>>> {
297302
&self.inh.adjustments

src/librustc_typeck/check/regionck.rs

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ use middle::ty::{ReScope};
126126
use middle::ty::{mod, Ty, MethodCall};
127127
use middle::infer;
128128
use middle::pat_util;
129-
use util::nodemap::{DefIdMap, NodeMap, FnvHashMap};
129+
use util::nodemap::{FnvHashMap};
130130
use util::ppaux::{ty_to_string, Repr};
131131

132132
use syntax::{ast, ast_util};
@@ -446,47 +446,6 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
446446
}
447447
}
448448

449-
impl<'fcx, 'tcx> mc::Typer<'tcx> for Rcx<'fcx, 'tcx> {
450-
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> {
451-
self.fcx.ccx.tcx
452-
}
453-
454-
fn node_ty(&self, id: ast::NodeId) -> mc::McResult<Ty<'tcx>> {
455-
let t = self.resolve_node_type(id);
456-
if ty::type_is_error(t) {Err(())} else {Ok(t)}
457-
}
458-
459-
fn node_method_ty(&self, method_call: MethodCall) -> Option<Ty<'tcx>> {
460-
self.resolve_method_type(method_call)
461-
}
462-
463-
fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment<'tcx>>> {
464-
&self.fcx.inh.adjustments
465-
}
466-
467-
fn is_method_call(&self, id: ast::NodeId) -> bool {
468-
self.fcx.inh.method_map.borrow().contains_key(&MethodCall::expr(id))
469-
}
470-
471-
fn temporary_scope(&self, id: ast::NodeId) -> Option<CodeExtent> {
472-
self.tcx().region_maps.temporary_scope(id)
473-
}
474-
475-
fn upvar_borrow(&self, id: ty::UpvarId) -> ty::UpvarBorrow {
476-
self.fcx.inh.upvar_borrow_map.borrow()[id].clone()
477-
}
478-
479-
fn capture_mode(&self, closure_expr_id: ast::NodeId)
480-
-> ast::CaptureClause {
481-
self.tcx().capture_modes.borrow()[closure_expr_id].clone()
482-
}
483-
484-
fn unboxed_closures<'a>(&'a self)
485-
-> &'a RefCell<DefIdMap<ty::UnboxedClosure<'tcx>>> {
486-
&self.fcx.inh.unboxed_closures
487-
}
488-
}
489-
490449
impl<'a, 'tcx, 'v> Visitor<'v> for Rcx<'a, 'tcx> {
491450
// (..) FIXME(#3238) should use visit_pat, not visit_arm/visit_local,
492451
// However, right now we run into an issue whereby some free
@@ -767,7 +726,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
767726
constrain_bindings_in_pat(&**pat, rcx);
768727

769728
{
770-
let mc = mc::MemCategorizationContext::new(rcx);
729+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
771730
let pat_ty = rcx.resolve_node_type(pat.id);
772731
let pat_cmt = mc.cat_rvalue(pat.id,
773732
pat.span,
@@ -1080,7 +1039,7 @@ fn constrain_callee(rcx: &mut Rcx,
10801039
ty::RegionTraitStore(r, _) => {
10811040
// While we're here, link the closure's region with a unique
10821041
// immutable borrow (gathered later in borrowck)
1083-
let mc = mc::MemCategorizationContext::new(rcx);
1042+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
10841043
let expr_cmt = ignore_err!(mc.cat_expr(callee_expr));
10851044
link_region(rcx, callee_expr.span, call_region,
10861045
ty::UniqueImmBorrow, expr_cmt);
@@ -1189,7 +1148,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
11891148
method.ty.repr(rcx.tcx()))[])
11901149
};
11911150
{
1192-
let mc = mc::MemCategorizationContext::new(rcx);
1151+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
11931152
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
11941153
link_region(rcx, deref_expr.span, r,
11951154
ty::BorrowKind::from_mutbl(m), self_cmt);
@@ -1285,7 +1244,7 @@ fn link_addr_of(rcx: &mut Rcx, expr: &ast::Expr,
12851244
debug!("link_addr_of(base=?)");
12861245

12871246
let cmt = {
1288-
let mc = mc::MemCategorizationContext::new(rcx);
1247+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
12891248
ignore_err!(mc.cat_expr(base))
12901249
};
12911250
link_region_from_node_type(rcx, expr.span, expr.id, mutability, cmt);
@@ -1300,7 +1259,7 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
13001259
None => { return; }
13011260
Some(ref expr) => &**expr,
13021261
};
1303-
let mc = mc::MemCategorizationContext::new(rcx);
1262+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
13041263
let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
13051264
link_pattern(rcx, mc, discr_cmt, &*local.pat);
13061265
}
@@ -1310,7 +1269,7 @@ fn link_local(rcx: &Rcx, local: &ast::Local) {
13101269
/// linked to the lifetime of its guarantor (if any).
13111270
fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
13121271
debug!("regionck::for_match()");
1313-
let mc = mc::MemCategorizationContext::new(rcx);
1272+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
13141273
let discr_cmt = ignore_err!(mc.cat_expr(discr));
13151274
debug!("discr_cmt={}", discr_cmt.repr(rcx.tcx()));
13161275
for arm in arms.iter() {
@@ -1325,7 +1284,7 @@ fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
13251284
/// linked to the lifetime of its guarantor (if any).
13261285
fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
13271286
debug!("regionck::link_fn_args(body_scope={})", body_scope);
1328-
let mc = mc::MemCategorizationContext::new(rcx);
1287+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
13291288
for arg in args.iter() {
13301289
let arg_ty = rcx.fcx.node_ty(arg.id);
13311290
let re_scope = ty::ReScope(body_scope);
@@ -1340,7 +1299,7 @@ fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
13401299
/// Link lifetimes of any ref bindings in `root_pat` to the pointers found in the discriminant, if
13411300
/// needed.
13421301
fn link_pattern<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
1343-
mc: mc::MemCategorizationContext<Rcx<'a, 'tcx>>,
1302+
mc: mc::MemCategorizationContext<FnCtxt<'a, 'tcx>>,
13441303
discr_cmt: mc::cmt<'tcx>,
13451304
root_pat: &ast::Pat) {
13461305
debug!("link_pattern(discr_cmt={}, root_pat={})",
@@ -1379,7 +1338,7 @@ fn link_autoref(rcx: &Rcx,
13791338
autoref: &ty::AutoRef) {
13801339

13811340
debug!("link_autoref(autoref={})", autoref);
1382-
let mc = mc::MemCategorizationContext::new(rcx);
1341+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
13831342
let expr_cmt = ignore_err!(mc.cat_expr_autoderefd(expr, autoderefs));
13841343
debug!("expr_cmt={}", expr_cmt.repr(rcx.tcx()));
13851344

@@ -1401,7 +1360,7 @@ fn link_by_ref(rcx: &Rcx,
14011360
let tcx = rcx.tcx();
14021361
debug!("link_by_ref(expr={}, callee_scope={})",
14031362
expr.repr(tcx), callee_scope);
1404-
let mc = mc::MemCategorizationContext::new(rcx);
1363+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
14051364
let expr_cmt = ignore_err!(mc.cat_expr(expr));
14061365
let borrow_region = ty::ReScope(callee_scope);
14071366
link_region(rcx, expr.span, borrow_region, ty::ImmBorrow, expr_cmt);
@@ -1669,7 +1628,7 @@ fn link_reborrowed_region<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
16691628
/// assignment expression.
16701629
fn adjust_borrow_kind_for_assignment_lhs(rcx: &Rcx,
16711630
lhs: &ast::Expr) {
1672-
let mc = mc::MemCategorizationContext::new(rcx);
1631+
let mc = mc::MemCategorizationContext::new(rcx.fcx);
16731632
let cmt = ignore_err!(mc.cat_expr(lhs));
16741633
adjust_upvar_borrow_kind_for_mut(rcx, cmt);
16751634
}

0 commit comments

Comments
 (0)