Skip to content

Commit 0053b44

Browse files
committed
rustc_typeck: Use Deref for FnCtxt, Inherited and InferCtxt fields and methods.
1 parent 76affa5 commit 0053b44

File tree

17 files changed

+804
-855
lines changed

17 files changed

+804
-855
lines changed

src/librustc_typeck/check/_match.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn bad_struct_kind_err(sess: &Session, pat: &hir::Pat, path: &hir::Path, lint: b
5858

5959
impl<'a, 'tcx> PatCtxt<'a, 'tcx, 'tcx> {
6060
pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
61-
let tcx = self.tcx();
61+
let tcx = self.tcx;
6262

6363
debug!("check_pat(pat={:?},expected={:?})", pat, expected);
6464

@@ -126,15 +126,15 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
126126
span_err!(tcx.sess, span, E0029,
127127
"only char and numeric types are allowed in range patterns\n \
128128
start type: {}\n end type: {}",
129-
self.infcx().ty_to_string(lhs_ty),
130-
self.infcx().ty_to_string(rhs_ty)
129+
self.ty_to_string(lhs_ty),
130+
self.ty_to_string(rhs_ty)
131131
);
132132
return;
133133
}
134134

135135
// Check that the types of the end-points can be unified.
136136
let types_unify = require_same_types(
137-
self.ccx, Some(self.infcx()), pat.span, rhs_ty, lhs_ty,
137+
self.ccx, Some(self), pat.span, rhs_ty, lhs_ty,
138138
"mismatched types in range",
139139
);
140140

@@ -145,7 +145,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
145145

146146
// Now that we know the types can be unified we find the unified type and use
147147
// it to type the entire expression.
148-
let common_type = self.infcx().resolve_type_vars_if_possible(&lhs_ty);
148+
let common_type = self.resolve_type_vars_if_possible(&lhs_ty);
149149

150150
self.write_ty(pat.id, common_type);
151151

@@ -181,7 +181,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
181181
// ref x | ref const x | ref mut x
182182
// then `x` is assigned a value of type `&M T` where M is the mutability
183183
// and T is the expected type.
184-
let region_var = self.infcx().next_region_var(infer::PatternRegion(pat.span));
184+
let region_var = self.next_region_var(infer::PatternRegion(pat.span));
185185
let mt = ty::TypeAndMut { ty: expected, mutbl: mutbl };
186186
let region_ty = tcx.mk_ref(tcx.mk_region(region_var), mt);
187187

@@ -227,14 +227,14 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
227227
let self_ty = self.to_ty(&qself.ty);
228228
let path_res = if let Some(&d) = tcx.def_map.borrow().get(&pat.id) {
229229
if d.base_def == Def::Err {
230-
self.infcx().set_tainted_by_errors();
230+
self.set_tainted_by_errors();
231231
self.write_error(pat.id);
232232
return;
233233
}
234234
d
235235
} else if qself.position == 0 {
236236
// This is just a sentinel for finish_resolving_def_to_ty.
237-
let sentinel = self.tcx().map.local_def_id(ast::CRATE_NODE_ID);
237+
let sentinel = self.tcx.map.local_def_id(ast::CRATE_NODE_ID);
238238
def::PathResolution {
239239
base_def: Def::Mod(sentinel),
240240
depth: path.segments.len()
@@ -264,8 +264,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
264264
}
265265
PatKind::Tup(ref elements) => {
266266
let element_tys: Vec<_> =
267-
(0..elements.len()).map(|_| self.infcx().next_ty_var())
268-
.collect();
267+
(0..elements.len()).map(|_| self.next_ty_var()).collect();
269268
let pat_ty = tcx.mk_tup(element_tys.clone());
270269
self.write_ty(pat.id, pat_ty);
271270
self.demand_eqtype(pat.span, expected, pat_ty);
@@ -274,7 +273,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
274273
}
275274
}
276275
PatKind::Box(ref inner) => {
277-
let inner_ty = self.infcx().next_ty_var();
276+
let inner_ty = self.next_ty_var();
278277
let uniq_ty = tcx.mk_box(inner_ty);
279278

280279
if self.check_dereferencable(pat.span, expected, &inner) {
@@ -290,7 +289,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
290289
}
291290
}
292291
PatKind::Ref(ref inner, mutbl) => {
293-
let expected = self.infcx().shallow_resolve(expected);
292+
let expected = self.shallow_resolve(expected);
294293
if self.check_dereferencable(pat.span, expected, &inner) {
295294
// `demand::subtype` would be good enough, but using
296295
// `eqtype` turns out to be equally general. See (*)
@@ -305,9 +304,9 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
305304
(expected, mt.ty)
306305
}
307306
_ => {
308-
let inner_ty = self.infcx().next_ty_var();
307+
let inner_ty = self.next_ty_var();
309308
let mt = ty::TypeAndMut { ty: inner_ty, mutbl: mutbl };
310-
let region = self.infcx().next_region_var(infer::PatternRegion(pat.span));
309+
let region = self.next_region_var(infer::PatternRegion(pat.span));
311310
let rptr_ty = tcx.mk_ref(tcx.mk_region(region), mt);
312311
self.demand_eqtype(pat.span, expected, rptr_ty);
313312
(rptr_ty, inner_ty)
@@ -323,7 +322,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
323322
}
324323
PatKind::Vec(ref before, ref slice, ref after) => {
325324
let expected_ty = self.structurally_resolved_type(pat.span, expected);
326-
let inner_ty = self.infcx().next_ty_var();
325+
let inner_ty = self.next_ty_var();
327326
let pat_ty = match expected_ty.sty {
328327
ty::TyArray(_, size) => tcx.mk_array(inner_ty, {
329328
let min_len = before.len() + after.len();
@@ -333,7 +332,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
333332
}
334333
}),
335334
_ => {
336-
let region = self.infcx().next_region_var(infer::PatternRegion(pat.span));
335+
let region = self.next_region_var(infer::PatternRegion(pat.span));
337336
tcx.mk_ref(tcx.mk_region(region), ty::TypeAndMut {
338337
ty: tcx.mk_slice(inner_ty),
339338
mutbl: expected_ty.builtin_deref(true, ty::NoPreference).map(|mt| mt.mutbl)
@@ -353,7 +352,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
353352
self.check_pat(&elt, inner_ty);
354353
}
355354
if let Some(ref slice) = *slice {
356-
let region = self.infcx().next_region_var(infer::PatternRegion(pat.span));
355+
let region = self.next_region_var(infer::PatternRegion(pat.span));
357356
let mutbl = expected_ty.builtin_deref(true, ty::NoPreference)
358357
.map_or(hir::MutImmutable, |mt| mt.mutbl);
359358

@@ -425,7 +424,7 @@ fn check_assoc_item_is_const(&self, def: Def, span: Span) -> bool {
425424
match def {
426425
Def::AssociatedConst(..) => true,
427426
Def::Method(..) => {
428-
span_err!(self.tcx().sess, span, E0327,
427+
span_err!(self.tcx.sess, span, E0327,
429428
"associated items in match patterns must be constants");
430429
false
431430
}
@@ -436,16 +435,16 @@ fn check_assoc_item_is_const(&self, def: Def, span: Span) -> bool {
436435
}
437436

438437
pub fn check_dereferencable(&self, span: Span, expected: Ty<'tcx>, inner: &hir::Pat) -> bool {
439-
let tcx = self.tcx();
438+
let tcx = self.tcx;
440439
if pat_is_binding(&tcx.def_map.borrow(), inner) {
441-
let expected = self.infcx().shallow_resolve(expected);
440+
let expected = self.shallow_resolve(expected);
442441
expected.builtin_deref(true, ty::NoPreference).map_or(true, |mt| match mt.ty.sty {
443442
ty::TyTrait(_) => {
444443
// This is "x = SomeTrait" being reduced from
445444
// "let &x = &SomeTrait" or "let box x = Box<SomeTrait>", an error.
446445
span_err!(tcx.sess, span, E0033,
447446
"type `{}` cannot be dereferenced",
448-
self.infcx().ty_to_string(expected));
447+
self.ty_to_string(expected));
449448
false
450449
}
451450
_ => true
@@ -463,7 +462,7 @@ pub fn check_match(&self,
463462
arms: &'tcx [hir::Arm],
464463
expected: Expectation<'tcx>,
465464
match_src: hir::MatchSource) {
466-
let tcx = self.tcx();
465+
let tcx = self.tcx;
467466

468467
// Not entirely obvious: if matches may create ref bindings, we
469468
// want to use the *precise* type of the discriminant, *not* some
@@ -482,7 +481,7 @@ pub fn check_match(&self,
482481
// ...but otherwise we want to use any supertype of the
483482
// discriminant. This is sort of a workaround, see note (*) in
484483
// `check_pat` for some details.
485-
discrim_ty = self.infcx().next_ty_var();
484+
discrim_ty = self.next_ty_var();
486485
self.check_expr_has_type(discrim, discrim_ty);
487486
};
488487

@@ -508,14 +507,14 @@ pub fn check_match(&self,
508507
// of execution reach it, we will panic, so bottom is an appropriate
509508
// type in that case)
510509
let expected = expected.adjust_for_branches(self);
511-
let mut result_ty = self.infcx().next_diverging_ty_var();
510+
let mut result_ty = self.next_diverging_ty_var();
512511
let coerce_first = match expected {
513512
// We don't coerce to `()` so that if the match expression is a
514513
// statement it's branches can have any consistent type. That allows
515514
// us to give better error messages (pointing to a usually better
516515
// arm for inconsistent arms or to the whole match when a `()` type
517516
// is required).
518-
Expectation::ExpectHasType(ety) if ety != self.tcx().mk_nil() => {
517+
Expectation::ExpectHasType(ety) if ety != self.tcx.mk_nil() => {
519518
ety
520519
}
521520
_ => result_ty
@@ -547,7 +546,7 @@ pub fn check_match(&self,
547546
};
548547

549548
let result = if is_if_let_fallback {
550-
self.infcx().eq_types(true, origin, arm_ty, result_ty)
549+
self.eq_types(true, origin, arm_ty, result_ty)
551550
.map(|InferOk { obligations, .. }| {
552551
// FIXME(#32730) propagate obligations
553552
assert!(obligations.is_empty());
@@ -569,8 +568,8 @@ pub fn check_match(&self,
569568
} else {
570569
(result_ty, arm_ty)
571570
};
572-
self.infcx().report_mismatched_types(origin, expected, found, e);
573-
self.tcx().types.err
571+
self.report_mismatched_types(origin, expected, found, e);
572+
self.tcx.types.err
574573
}
575574
};
576575
}
@@ -583,7 +582,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx, 'tcx> {
583582
pub fn check_pat_struct(&self, pat: &'tcx hir::Pat,
584583
path: &hir::Path, fields: &'tcx [Spanned<hir::FieldPat>],
585584
etc: bool, expected: Ty<'tcx>) {
586-
let tcx = self.tcx();
585+
let tcx = self.tcx;
587586

588587
let def = tcx.def_map.borrow().get(&pat.id).unwrap().full_def();
589588
let variant = match self.def_struct_variant(def, path.span) {
@@ -621,12 +620,12 @@ fn check_pat_enum(&self,
621620
is_tuple_struct_pat: bool)
622621
{
623622
// Typecheck the path.
624-
let tcx = self.tcx();
623+
let tcx = self.tcx;
625624

626625
let path_res = match tcx.def_map.borrow().get(&pat.id) {
627626
Some(&path_res) if path_res.base_def != Def::Err => path_res,
628627
_ => {
629-
self.infcx().set_tainted_by_errors();
628+
self.set_tainted_by_errors();
630629
self.write_error(pat.id);
631630

632631
if let Some(subpats) = subpats {
@@ -767,7 +766,7 @@ pub fn check_struct_pat_fields(&self,
767766
variant: ty::VariantDef<'tcx>,
768767
substs: &Substs<'tcx>,
769768
etc: bool) {
770-
let tcx = self.tcx();
769+
let tcx = self.tcx;
771770

772771
// Index the struct fields' types.
773772
let field_map = variant.fields

src/librustc_typeck/check/callee.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ fn try_overloaded_call_step(&self,
128128
// Check whether this is a call to a closure where we
129129
// haven't yet decided on whether the closure is fn vs
130130
// fnmut vs fnonce. If so, we have to defer further processing.
131-
if self.infcx().closure_kind(def_id).is_none() {
131+
if self.closure_kind(def_id).is_none() {
132132
let closure_ty =
133-
self.infcx().closure_type(def_id, substs);
133+
self.closure_type(def_id, substs);
134134
let fn_sig =
135-
self.infcx().replace_late_bound_regions_with_fresh_var(call_expr.span,
136-
infer::FnCall,
137-
&closure_ty.sig).0;
135+
self.replace_late_bound_regions_with_fresh_var(call_expr.span,
136+
infer::FnCall,
137+
&closure_ty.sig).0;
138138
self.record_deferred_call_resolution(def_id, Box::new(CallResolution {
139139
call_expr: call_expr,
140140
callee_expr: callee_expr,
@@ -175,9 +175,9 @@ fn try_overloaded_call_traits(&self,
175175
{
176176
// Try the options that are least restrictive on the caller first.
177177
for &(opt_trait_def_id, method_name) in &[
178-
(self.tcx().lang_items.fn_trait(), token::intern("call")),
179-
(self.tcx().lang_items.fn_mut_trait(), token::intern("call_mut")),
180-
(self.tcx().lang_items.fn_once_trait(), token::intern("call_once")),
178+
(self.tcx.lang_items.fn_trait(), token::intern("call")),
179+
(self.tcx.lang_items.fn_mut_trait(), token::intern("call_mut")),
180+
(self.tcx.lang_items.fn_once_trait(), token::intern("call_once")),
181181
] {
182182
let trait_def_id = match opt_trait_def_id {
183183
Some(def_id) => def_id,
@@ -221,7 +221,7 @@ fn confirm_builtin_call(&self,
221221
}, callee_ty, None);
222222

223223
if let hir::ExprCall(ref expr, _) = call_expr.node {
224-
let tcx = self.tcx();
224+
let tcx = self.tcx;
225225
if let Some(pr) = tcx.def_map.borrow().get(&expr.id) {
226226
if pr.depth == 0 && pr.base_def != Def::Err {
227227
if let Some(span) = tcx.map.span_if_local(pr.def_id()) {
@@ -238,7 +238,7 @@ fn confirm_builtin_call(&self,
238238
// set up all the node type bindings.
239239
error_fn_sig = ty::Binder(ty::FnSig {
240240
inputs: self.err_args(arg_exprs.len()),
241-
output: ty::FnConverging(self.tcx().types.err),
241+
output: ty::FnConverging(self.tcx.types.err),
242242
variadic: false
243243
});
244244

@@ -252,9 +252,9 @@ fn confirm_builtin_call(&self,
252252
// previously appeared within a `Binder<>` and hence would not
253253
// have been normalized before.
254254
let fn_sig =
255-
self.infcx().replace_late_bound_regions_with_fresh_var(call_expr.span,
256-
infer::FnCall,
257-
fn_sig).0;
255+
self.replace_late_bound_regions_with_fresh_var(call_expr.span,
256+
infer::FnCall,
257+
fn_sig).0;
258258
let fn_sig =
259259
self.normalize_associated_types_in(call_expr.span, &fn_sig);
260260

@@ -323,7 +323,7 @@ fn write_overloaded_call_method_map(&self,
323323
call_expr: &hir::Expr,
324324
method_callee: ty::MethodCallee<'tcx>) {
325325
let method_call = ty::MethodCall::expr(call_expr.id);
326-
self.inh.tables.borrow_mut().method_map.insert(method_call, method_callee);
326+
self.tables.borrow_mut().method_map.insert(method_call, method_callee);
327327
}
328328
}
329329

@@ -344,7 +344,7 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
344344

345345
// we should not be invoked until the closure kind has been
346346
// determined by upvar inference
347-
assert!(fcx.infcx().closure_kind(self.closure_def_id).is_some());
347+
assert!(fcx.closure_kind(self.closure_def_id).is_some());
348348

349349
// We may now know enough to figure out fn vs fnmut etc.
350350
match fcx.try_overloaded_call_traits(self.call_expr, self.callee_expr,
@@ -358,8 +358,8 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
358358
// can't because of the annoying need for a TypeTrace.
359359
// (This always bites me, should find a way to
360360
// refactor it.)
361-
let method_sig = fcx.tcx().no_late_bound_regions(method_callee.ty.fn_sig())
362-
.unwrap();
361+
let method_sig = fcx.tcx.no_late_bound_regions(method_callee.ty.fn_sig())
362+
.unwrap();
363363

364364
debug!("attempt_resolution: method_callee={:?}",
365365
method_callee);
@@ -370,7 +370,7 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
370370
fcx.demand_eqtype(self.call_expr.span, self_arg_ty, method_arg_ty);
371371
}
372372

373-
let nilty = fcx.tcx().mk_nil();
373+
let nilty = fcx.tcx.mk_nil();
374374
fcx.demand_eqtype(self.call_expr.span,
375375
method_sig.output.unwrap_or(nilty),
376376
self.fn_sig.output.unwrap_or(nilty));

0 commit comments

Comments
 (0)