@@ -106,7 +106,6 @@ mod relate_tys;
106
106
/// # Parameters
107
107
///
108
108
/// - `infcx` -- inference context to use
109
- /// - `param_env` -- parameter environment to use for trait solving
110
109
/// - `body` -- MIR body to type-check
111
110
/// - `promoted` -- map of promoted constants within `body`
112
111
/// - `universal_regions` -- the universal regions from `body`s function signature
@@ -154,7 +153,7 @@ pub(crate) fn type_check<'a, 'tcx>(
154
153
155
154
debug ! ( ?normalized_inputs_and_output) ;
156
155
157
- let mut checker = TypeChecker {
156
+ let mut typeck = TypeChecker {
158
157
infcx,
159
158
last_span : body. span ,
160
159
body,
@@ -170,23 +169,22 @@ pub(crate) fn type_check<'a, 'tcx>(
170
169
constraints : & mut constraints,
171
170
} ;
172
171
173
- checker . check_user_type_annotations ( ) ;
172
+ typeck . check_user_type_annotations ( ) ;
174
173
175
- let mut verifier = TypeVerifier { cx : & mut checker , promoted, last_span : body. span } ;
174
+ let mut verifier = TypeVerifier { typeck : & mut typeck , promoted, last_span : body. span } ;
176
175
verifier. visit_body ( body) ;
177
176
178
- checker . typeck_mir ( body) ;
179
- checker . equate_inputs_and_outputs ( body, & normalized_inputs_and_output) ;
180
- checker . check_signature_annotation ( body) ;
177
+ typeck . typeck_mir ( body) ;
178
+ typeck . equate_inputs_and_outputs ( body, & normalized_inputs_and_output) ;
179
+ typeck . check_signature_annotation ( body) ;
181
180
182
- liveness:: generate ( & mut checker , body, & elements, flow_inits, move_data) ;
181
+ liveness:: generate ( & mut typeck , body, & elements, flow_inits, move_data) ;
183
182
184
- let opaque_type_values = infcx. take_opaque_types ( ) ;
185
-
186
- let opaque_type_values = opaque_type_values
183
+ let opaque_type_values = infcx
184
+ . take_opaque_types ( )
187
185
. into_iter ( )
188
186
. map ( |( opaque_type_key, decl) | {
189
- let _: Result < _ , ErrorGuaranteed > = checker . fully_perform_op (
187
+ let _: Result < _ , ErrorGuaranteed > = typeck . fully_perform_op (
190
188
Locations :: All ( body. span ) ,
191
189
ConstraintCategory :: OpaqueType ,
192
190
CustomTypeOp :: new (
@@ -216,11 +214,11 @@ pub(crate) fn type_check<'a, 'tcx>(
216
214
match region. kind ( ) {
217
215
ty:: ReVar ( _) => region,
218
216
ty:: RePlaceholder ( placeholder) => {
219
- checker . constraints . placeholder_region ( infcx, placeholder)
217
+ typeck . constraints . placeholder_region ( infcx, placeholder)
220
218
}
221
219
_ => ty:: Region :: new_var (
222
220
infcx. tcx ,
223
- checker . universal_regions . to_region_vid ( region) ,
221
+ typeck . universal_regions . to_region_vid ( region) ,
224
222
) ,
225
223
}
226
224
} ) ;
@@ -250,7 +248,7 @@ enum FieldAccessError {
250
248
/// type, calling `span_mirbug` and returning an error type if there
251
249
/// is a problem.
252
250
struct TypeVerifier < ' a , ' b , ' tcx > {
253
- cx : & ' a mut TypeChecker < ' b , ' tcx > ,
251
+ typeck : & ' a mut TypeChecker < ' b , ' tcx > ,
254
252
promoted : & ' b IndexSlice < Promoted , Body < ' tcx > > ,
255
253
last_span : Span ,
256
254
}
@@ -272,9 +270,9 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
272
270
self . super_const_operand ( constant, location) ;
273
271
let ty = self . sanitize_type ( constant, constant. const_ . ty ( ) ) ;
274
272
275
- self . cx . infcx . tcx . for_each_free_region ( & ty, |live_region| {
276
- let live_region_vid = self . cx . universal_regions . to_region_vid ( live_region) ;
277
- self . cx . constraints . liveness_constraints . add_location ( live_region_vid, location) ;
273
+ self . typeck . infcx . tcx . for_each_free_region ( & ty, |live_region| {
274
+ let live_region_vid = self . typeck . universal_regions . to_region_vid ( live_region) ;
275
+ self . typeck . constraints . liveness_constraints . add_location ( live_region_vid, location) ;
278
276
} ) ;
279
277
280
278
// HACK(compiler-errors): Constants that are gathered into Body.required_consts
@@ -286,14 +284,14 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
286
284
} ;
287
285
288
286
if let Some ( annotation_index) = constant. user_ty {
289
- if let Err ( terr) = self . cx . relate_type_and_user_type (
287
+ if let Err ( terr) = self . typeck . relate_type_and_user_type (
290
288
constant. const_ . ty ( ) ,
291
289
ty:: Invariant ,
292
290
& UserTypeProjection { base : annotation_index, projs : vec ! [ ] } ,
293
291
locations,
294
292
ConstraintCategory :: Boring ,
295
293
) {
296
- let annotation = & self . cx . user_type_annotations [ annotation_index] ;
294
+ let annotation = & self . typeck . user_type_annotations [ annotation_index] ;
297
295
span_mirbug ! (
298
296
self ,
299
297
constant,
@@ -322,9 +320,12 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
322
320
promoted : & Body < ' tcx > ,
323
321
ty,
324
322
san_ty| {
325
- if let Err ( terr) =
326
- verifier. cx . eq_types ( ty, san_ty, locations, ConstraintCategory :: Boring )
327
- {
323
+ if let Err ( terr) = verifier. typeck . eq_types (
324
+ ty,
325
+ san_ty,
326
+ locations,
327
+ ConstraintCategory :: Boring ,
328
+ ) {
328
329
span_mirbug ! (
329
330
verifier,
330
331
promoted,
@@ -342,18 +343,18 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
342
343
let promoted_ty = promoted_body. return_ty ( ) ;
343
344
check_err ( self , promoted_body, ty, promoted_ty) ;
344
345
} else {
345
- self . cx . ascribe_user_type (
346
+ self . typeck . ascribe_user_type (
346
347
constant. const_ . ty ( ) ,
347
348
UserType :: TypeOf ( uv. def , UserArgs { args : uv. args , user_self_ty : None } ) ,
348
- locations. span ( self . cx . body ) ,
349
+ locations. span ( self . typeck . body ) ,
349
350
) ;
350
351
}
351
352
} else if let Some ( static_def_id) = constant. check_static_ptr ( tcx) {
352
353
let unnormalized_ty = tcx. type_of ( static_def_id) . instantiate_identity ( ) ;
353
- let normalized_ty = self . cx . normalize ( unnormalized_ty, locations) ;
354
+ let normalized_ty = self . typeck . normalize ( unnormalized_ty, locations) ;
354
355
let literal_ty = constant. const_ . ty ( ) . builtin_deref ( true ) . unwrap ( ) ;
355
356
356
- if let Err ( terr) = self . cx . eq_types (
357
+ if let Err ( terr) = self . typeck . eq_types (
357
358
literal_ty,
358
359
normalized_ty,
359
360
locations,
@@ -365,7 +366,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
365
366
366
367
if let ty:: FnDef ( def_id, args) = * constant. const_ . ty ( ) . kind ( ) {
367
368
let instantiated_predicates = tcx. predicates_of ( def_id) . instantiate ( tcx, args) ;
368
- self . cx . normalize_and_prove_instantiated_predicates (
369
+ self . typeck . normalize_and_prove_instantiated_predicates (
369
370
def_id,
370
371
instantiated_predicates,
371
372
locations,
@@ -375,7 +376,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
375
376
tcx. impl_of_method( def_id) . map( |imp| tcx. def_kind( imp) ) ,
376
377
Some ( DefKind :: Impl { of_trait: true } )
377
378
) ) ;
378
- self . cx . prove_predicates (
379
+ self . typeck . prove_predicates (
379
380
args. types ( ) . map ( |ty| ty:: ClauseKind :: WellFormed ( ty. into ( ) ) ) ,
380
381
locations,
381
382
ConstraintCategory :: Boring ,
@@ -409,7 +410,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
409
410
local_decl. ty
410
411
} ;
411
412
412
- if let Err ( terr) = self . cx . relate_type_and_user_type (
413
+ if let Err ( terr) = self . typeck . relate_type_and_user_type (
413
414
ty,
414
415
ty:: Invariant ,
415
416
user_ty,
@@ -439,11 +440,11 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
439
440
440
441
impl < ' a , ' b , ' tcx > TypeVerifier < ' a , ' b , ' tcx > {
441
442
fn body ( & self ) -> & Body < ' tcx > {
442
- self . cx . body
443
+ self . typeck . body
443
444
}
444
445
445
446
fn tcx ( & self ) -> TyCtxt < ' tcx > {
446
- self . cx . infcx . tcx
447
+ self . typeck . infcx . tcx
447
448
}
448
449
449
450
fn sanitize_type ( & mut self , parent : & dyn fmt:: Debug , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
@@ -493,7 +494,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
493
494
// whether the bounds fully apply: in effect, the rule is
494
495
// that if a value of some type could implement `Copy`, then
495
496
// it must.
496
- self . cx . prove_trait_ref (
497
+ self . typeck . prove_trait_ref (
497
498
trait_ref,
498
499
location. to_locations ( ) ,
499
500
ConstraintCategory :: CopyBound ,
@@ -508,7 +509,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
508
509
// checker on the promoted MIR, then transfer the constraints back to
509
510
// the main MIR, changing the locations to the provided location.
510
511
511
- let parent_body = mem:: replace ( & mut self . cx . body , promoted_body) ;
512
+ let parent_body = mem:: replace ( & mut self . typeck . body , promoted_body) ;
512
513
513
514
// Use new sets of constraints and closure bounds so that we can
514
515
// modify their locations.
@@ -519,18 +520,18 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
519
520
// Don't try to add borrow_region facts for the promoted MIR
520
521
521
522
let mut swap_constraints = |this : & mut Self | {
522
- mem:: swap ( this. cx . all_facts , all_facts) ;
523
- mem:: swap ( & mut this. cx . constraints . outlives_constraints , & mut constraints) ;
524
- mem:: swap ( & mut this. cx . constraints . liveness_constraints , & mut liveness_constraints) ;
523
+ mem:: swap ( this. typeck . all_facts , all_facts) ;
524
+ mem:: swap ( & mut this. typeck . constraints . outlives_constraints , & mut constraints) ;
525
+ mem:: swap ( & mut this. typeck . constraints . liveness_constraints , & mut liveness_constraints) ;
525
526
} ;
526
527
527
528
swap_constraints ( self ) ;
528
529
529
530
self . visit_body ( promoted_body) ;
530
531
531
- self . cx . typeck_mir ( promoted_body) ;
532
+ self . typeck . typeck_mir ( promoted_body) ;
532
533
533
- self . cx . body = parent_body;
534
+ self . typeck . body = parent_body;
534
535
// Merge the outlives constraints back in, at the given location.
535
536
swap_constraints ( self ) ;
536
537
@@ -546,7 +547,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
546
547
// temporary from the user's point of view.
547
548
constraint. category = ConstraintCategory :: Boring ;
548
549
}
549
- self . cx . constraints . outlives_constraints . push ( constraint)
550
+ self . typeck . constraints . outlives_constraints . push ( constraint)
550
551
}
551
552
// If the region is live at least one location in the promoted MIR,
552
553
// then add a liveness constraint to the main MIR for this region
@@ -556,7 +557,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
556
557
// unordered.
557
558
#[ allow( rustc:: potential_query_instability) ]
558
559
for region in liveness_constraints. live_regions_unordered ( ) {
559
- self . cx . constraints . liveness_constraints . add_location ( region, location) ;
560
+ self . typeck . constraints . liveness_constraints . add_location ( region, location) ;
560
561
}
561
562
}
562
563
@@ -640,13 +641,13 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
640
641
} ,
641
642
ProjectionElem :: Field ( field, fty) => {
642
643
let fty = self . sanitize_type ( place, fty) ;
643
- let fty = self . cx . normalize ( fty, location) ;
644
+ let fty = self . typeck . normalize ( fty, location) ;
644
645
match self . field_ty ( place, base, field, location) {
645
646
Ok ( ty) => {
646
- let ty = self . cx . normalize ( ty, location) ;
647
+ let ty = self . typeck . normalize ( ty, location) ;
647
648
debug ! ( ?fty, ?ty) ;
648
649
649
- if let Err ( terr) = self . cx . relate_types (
650
+ if let Err ( terr) = self . typeck . relate_types (
650
651
ty,
651
652
self . get_ambient_variance ( context) ,
652
653
fty,
@@ -678,8 +679,8 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
678
679
}
679
680
ProjectionElem :: OpaqueCast ( ty) => {
680
681
let ty = self . sanitize_type ( place, ty) ;
681
- let ty = self . cx . normalize ( ty, location) ;
682
- self . cx
682
+ let ty = self . typeck . normalize ( ty, location) ;
683
+ self . typeck
683
684
. relate_types (
684
685
ty,
685
686
self . get_ambient_variance ( context) ,
@@ -788,7 +789,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
788
789
} ;
789
790
790
791
if let Some ( field) = variant. fields . get ( field) {
791
- Ok ( self . cx . normalize ( field. ty ( tcx, args) , location) )
792
+ Ok ( self . typeck . normalize ( field. ty ( tcx, args) , location) )
792
793
} else {
793
794
Err ( FieldAccessError :: OutOfRange { field_count : variant. fields . len ( ) } )
794
795
}
0 commit comments