@@ -58,7 +58,7 @@ fn bad_struct_kind_err(sess: &Session, pat: &hir::Pat, path: &hir::Path, lint: b
58
58
59
59
impl < ' a , ' tcx > PatCtxt < ' a , ' tcx , ' tcx > {
60
60
pub fn check_pat ( & self , pat : & ' tcx hir:: Pat , expected : Ty < ' tcx > ) {
61
- let tcx = self . tcx ( ) ;
61
+ let tcx = self . tcx ;
62
62
63
63
debug ! ( "check_pat(pat={:?},expected={:?})" , pat, expected) ;
64
64
@@ -126,15 +126,15 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
126
126
span_err ! ( tcx. sess, span, E0029 ,
127
127
"only char and numeric types are allowed in range patterns\n \
128
128
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)
131
131
) ;
132
132
return ;
133
133
}
134
134
135
135
// Check that the types of the end-points can be unified.
136
136
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,
138
138
"mismatched types in range" ,
139
139
) ;
140
140
@@ -145,7 +145,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
145
145
146
146
// Now that we know the types can be unified we find the unified type and use
147
147
// 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) ;
149
149
150
150
self . write_ty ( pat. id , common_type) ;
151
151
@@ -181,7 +181,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
181
181
// ref x | ref const x | ref mut x
182
182
// then `x` is assigned a value of type `&M T` where M is the mutability
183
183
// 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 ) ) ;
185
185
let mt = ty:: TypeAndMut { ty : expected, mutbl : mutbl } ;
186
186
let region_ty = tcx. mk_ref ( tcx. mk_region ( region_var) , mt) ;
187
187
@@ -227,14 +227,14 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
227
227
let self_ty = self . to_ty ( & qself. ty ) ;
228
228
let path_res = if let Some ( & d) = tcx. def_map . borrow ( ) . get ( & pat. id ) {
229
229
if d. base_def == Def :: Err {
230
- self . infcx ( ) . set_tainted_by_errors ( ) ;
230
+ self . set_tainted_by_errors ( ) ;
231
231
self . write_error ( pat. id ) ;
232
232
return ;
233
233
}
234
234
d
235
235
} else if qself. position == 0 {
236
236
// 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 ) ;
238
238
def:: PathResolution {
239
239
base_def : Def :: Mod ( sentinel) ,
240
240
depth : path. segments . len ( )
@@ -264,8 +264,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
264
264
}
265
265
PatKind :: Tup ( ref elements) => {
266
266
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 ( ) ;
269
268
let pat_ty = tcx. mk_tup ( element_tys. clone ( ) ) ;
270
269
self . write_ty ( pat. id , pat_ty) ;
271
270
self . demand_eqtype ( pat. span , expected, pat_ty) ;
@@ -274,7 +273,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
274
273
}
275
274
}
276
275
PatKind :: Box ( ref inner) => {
277
- let inner_ty = self . infcx ( ) . next_ty_var ( ) ;
276
+ let inner_ty = self . next_ty_var ( ) ;
278
277
let uniq_ty = tcx. mk_box ( inner_ty) ;
279
278
280
279
if self . check_dereferencable ( pat. span , expected, & inner) {
@@ -290,7 +289,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
290
289
}
291
290
}
292
291
PatKind :: Ref ( ref inner, mutbl) => {
293
- let expected = self . infcx ( ) . shallow_resolve ( expected) ;
292
+ let expected = self . shallow_resolve ( expected) ;
294
293
if self . check_dereferencable ( pat. span , expected, & inner) {
295
294
// `demand::subtype` would be good enough, but using
296
295
// `eqtype` turns out to be equally general. See (*)
@@ -305,9 +304,9 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
305
304
( expected, mt. ty )
306
305
}
307
306
_ => {
308
- let inner_ty = self . infcx ( ) . next_ty_var ( ) ;
307
+ let inner_ty = self . next_ty_var ( ) ;
309
308
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 ) ) ;
311
310
let rptr_ty = tcx. mk_ref ( tcx. mk_region ( region) , mt) ;
312
311
self . demand_eqtype ( pat. span , expected, rptr_ty) ;
313
312
( rptr_ty, inner_ty)
@@ -323,7 +322,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
323
322
}
324
323
PatKind :: Vec ( ref before, ref slice, ref after) => {
325
324
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 ( ) ;
327
326
let pat_ty = match expected_ty. sty {
328
327
ty:: TyArray ( _, size) => tcx. mk_array ( inner_ty, {
329
328
let min_len = before. len ( ) + after. len ( ) ;
@@ -333,7 +332,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
333
332
}
334
333
} ) ,
335
334
_ => {
336
- let region = self . infcx ( ) . next_region_var ( infer:: PatternRegion ( pat. span ) ) ;
335
+ let region = self . next_region_var ( infer:: PatternRegion ( pat. span ) ) ;
337
336
tcx. mk_ref ( tcx. mk_region ( region) , ty:: TypeAndMut {
338
337
ty : tcx. mk_slice ( inner_ty) ,
339
338
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>) {
353
352
self . check_pat ( & elt, inner_ty) ;
354
353
}
355
354
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 ) ) ;
357
356
let mutbl = expected_ty. builtin_deref ( true , ty:: NoPreference )
358
357
. map_or ( hir:: MutImmutable , |mt| mt. mutbl ) ;
359
358
@@ -425,7 +424,7 @@ fn check_assoc_item_is_const(&self, def: Def, span: Span) -> bool {
425
424
match def {
426
425
Def :: AssociatedConst ( ..) => true ,
427
426
Def :: Method ( ..) => {
428
- span_err ! ( self . tcx( ) . sess, span, E0327 ,
427
+ span_err ! ( self . tcx. sess, span, E0327 ,
429
428
"associated items in match patterns must be constants" ) ;
430
429
false
431
430
}
@@ -436,16 +435,16 @@ fn check_assoc_item_is_const(&self, def: Def, span: Span) -> bool {
436
435
}
437
436
438
437
pub fn check_dereferencable ( & self , span : Span , expected : Ty < ' tcx > , inner : & hir:: Pat ) -> bool {
439
- let tcx = self . tcx ( ) ;
438
+ let tcx = self . tcx ;
440
439
if pat_is_binding ( & tcx. def_map . borrow ( ) , inner) {
441
- let expected = self . infcx ( ) . shallow_resolve ( expected) ;
440
+ let expected = self . shallow_resolve ( expected) ;
442
441
expected. builtin_deref ( true , ty:: NoPreference ) . map_or ( true , |mt| match mt. ty . sty {
443
442
ty:: TyTrait ( _) => {
444
443
// This is "x = SomeTrait" being reduced from
445
444
// "let &x = &SomeTrait" or "let box x = Box<SomeTrait>", an error.
446
445
span_err ! ( tcx. sess, span, E0033 ,
447
446
"type `{}` cannot be dereferenced" ,
448
- self . infcx ( ) . ty_to_string( expected) ) ;
447
+ self . ty_to_string( expected) ) ;
449
448
false
450
449
}
451
450
_ => true
@@ -463,7 +462,7 @@ pub fn check_match(&self,
463
462
arms : & ' tcx [ hir:: Arm ] ,
464
463
expected : Expectation < ' tcx > ,
465
464
match_src : hir:: MatchSource ) {
466
- let tcx = self . tcx ( ) ;
465
+ let tcx = self . tcx ;
467
466
468
467
// Not entirely obvious: if matches may create ref bindings, we
469
468
// want to use the *precise* type of the discriminant, *not* some
@@ -482,7 +481,7 @@ pub fn check_match(&self,
482
481
// ...but otherwise we want to use any supertype of the
483
482
// discriminant. This is sort of a workaround, see note (*) in
484
483
// `check_pat` for some details.
485
- discrim_ty = self . infcx ( ) . next_ty_var ( ) ;
484
+ discrim_ty = self . next_ty_var ( ) ;
486
485
self . check_expr_has_type ( discrim, discrim_ty) ;
487
486
} ;
488
487
@@ -508,14 +507,14 @@ pub fn check_match(&self,
508
507
// of execution reach it, we will panic, so bottom is an appropriate
509
508
// type in that case)
510
509
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 ( ) ;
512
511
let coerce_first = match expected {
513
512
// We don't coerce to `()` so that if the match expression is a
514
513
// statement it's branches can have any consistent type. That allows
515
514
// us to give better error messages (pointing to a usually better
516
515
// arm for inconsistent arms or to the whole match when a `()` type
517
516
// is required).
518
- Expectation :: ExpectHasType ( ety) if ety != self . tcx ( ) . mk_nil ( ) => {
517
+ Expectation :: ExpectHasType ( ety) if ety != self . tcx . mk_nil ( ) => {
519
518
ety
520
519
}
521
520
_ => result_ty
@@ -547,7 +546,7 @@ pub fn check_match(&self,
547
546
} ;
548
547
549
548
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)
551
550
. map ( |InferOk { obligations, .. } | {
552
551
// FIXME(#32730) propagate obligations
553
552
assert ! ( obligations. is_empty( ) ) ;
@@ -569,8 +568,8 @@ pub fn check_match(&self,
569
568
} else {
570
569
( result_ty, arm_ty)
571
570
} ;
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
574
573
}
575
574
} ;
576
575
}
@@ -583,7 +582,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx, 'tcx> {
583
582
pub fn check_pat_struct ( & self , pat : & ' tcx hir:: Pat ,
584
583
path : & hir:: Path , fields : & ' tcx [ Spanned < hir:: FieldPat > ] ,
585
584
etc : bool , expected : Ty < ' tcx > ) {
586
- let tcx = self . tcx ( ) ;
585
+ let tcx = self . tcx ;
587
586
588
587
let def = tcx. def_map . borrow ( ) . get ( & pat. id ) . unwrap ( ) . full_def ( ) ;
589
588
let variant = match self . def_struct_variant ( def, path. span ) {
@@ -621,12 +620,12 @@ fn check_pat_enum(&self,
621
620
is_tuple_struct_pat : bool )
622
621
{
623
622
// Typecheck the path.
624
- let tcx = self . tcx ( ) ;
623
+ let tcx = self . tcx ;
625
624
626
625
let path_res = match tcx. def_map . borrow ( ) . get ( & pat. id ) {
627
626
Some ( & path_res) if path_res. base_def != Def :: Err => path_res,
628
627
_ => {
629
- self . infcx ( ) . set_tainted_by_errors ( ) ;
628
+ self . set_tainted_by_errors ( ) ;
630
629
self . write_error ( pat. id ) ;
631
630
632
631
if let Some ( subpats) = subpats {
@@ -767,7 +766,7 @@ pub fn check_struct_pat_fields(&self,
767
766
variant : ty:: VariantDef < ' tcx > ,
768
767
substs : & Substs < ' tcx > ,
769
768
etc : bool ) {
770
- let tcx = self . tcx ( ) ;
769
+ let tcx = self . tcx ;
771
770
772
771
// Index the struct fields' types.
773
772
let field_map = variant. fields
0 commit comments