@@ -39,7 +39,8 @@ use rustc::ty::fold::TypeFoldable;
39
39
use rustc:: ty:: subst:: { Subst , SubstsRef , UnpackedKind , UserSubsts } ;
40
40
use rustc:: ty:: {
41
41
self , RegionVid , ToPolyTraitRef , Ty , TyCtxt , TyKind , UserType ,
42
- CanonicalUserTypeAnnotation , UserTypeAnnotationIndex ,
42
+ CanonicalUserTypeAnnotation , CanonicalUserTypeAnnotations ,
43
+ UserTypeAnnotationIndex ,
43
44
} ;
44
45
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
45
46
use rustc_data_structures:: indexed_vec:: { IndexVec , Idx } ;
@@ -283,7 +284,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
283
284
location. to_locations ( ) ,
284
285
ConstraintCategory :: Boring ,
285
286
) {
286
- let annotation = & self . mir . user_type_annotations [ annotation_index] ;
287
+ let annotation = & self . cx . user_type_annotations [ annotation_index] ;
287
288
span_mirbug ! (
288
289
self ,
289
290
constant,
@@ -550,8 +551,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
550
551
// checker on the promoted MIR, then transfer the constraints back to
551
552
// the main MIR, changing the locations to the provided location.
552
553
553
- let main_mir = mem:: replace ( & mut self . mir , promoted_mir) ;
554
- self . cx . mir = promoted_mir;
554
+ let parent_mir = mem:: replace ( & mut self . mir , promoted_mir) ;
555
555
556
556
let all_facts = & mut None ;
557
557
let mut constraints = Default :: default ( ) ;
@@ -573,8 +573,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
573
573
self . cx . typeck_mir ( promoted_mir) ;
574
574
}
575
575
576
- self . mir = main_mir;
577
- self . cx . mir = main_mir;
576
+ self . mir = parent_mir;
578
577
// Merge the outlives constraints back in, at the given location.
579
578
if let Some ( ref mut base_bcx) = self . cx . borrowck_context {
580
579
mem:: swap ( base_bcx. all_facts , all_facts) ;
@@ -818,7 +817,9 @@ struct TypeChecker<'a, 'gcx: 'tcx, 'tcx: 'a> {
818
817
infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
819
818
param_env : ty:: ParamEnv < ' gcx > ,
820
819
last_span : Span ,
821
- mir : & ' a Mir < ' tcx > ,
820
+ /// User type annotations are shared between the main MIR and the MIR of
821
+ /// all of the promoted items.
822
+ user_type_annotations : & ' a CanonicalUserTypeAnnotations < ' tcx > ,
822
823
mir_def_id : DefId ,
823
824
region_bound_pairs : & ' a RegionBoundPairs < ' tcx > ,
824
825
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
@@ -973,8 +974,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
973
974
let mut checker = Self {
974
975
infcx,
975
976
last_span : DUMMY_SP ,
976
- mir,
977
977
mir_def_id,
978
+ user_type_annotations : & mir. user_type_annotations ,
978
979
param_env,
979
980
region_bound_pairs,
980
981
implicit_region_bound,
@@ -990,9 +991,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
990
991
fn check_user_type_annotations ( & mut self ) {
991
992
debug ! (
992
993
"check_user_type_annotations: user_type_annotations={:?}" ,
993
- self . mir . user_type_annotations
994
+ self . user_type_annotations
994
995
) ;
995
- for user_annotation in & self . mir . user_type_annotations {
996
+ for user_annotation in self . user_type_annotations {
996
997
let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = * user_annotation;
997
998
let ( annotation, _) = self . infcx . instantiate_canonical_with_fresh_inference_vars (
998
999
span, user_ty
@@ -1175,7 +1176,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1175
1176
a, v, user_ty, locations,
1176
1177
) ;
1177
1178
1178
- let annotated_type = self . mir . user_type_annotations [ user_ty. base ] . inferred_ty ;
1179
+ let annotated_type = self . user_type_annotations [ user_ty. base ] . inferred_ty ;
1179
1180
let mut curr_projected_ty = PlaceTy :: from_ty ( annotated_type) ;
1180
1181
1181
1182
let tcx = self . infcx . tcx ;
@@ -1361,7 +1362,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1361
1362
location. to_locations ( ) ,
1362
1363
ConstraintCategory :: Boring ,
1363
1364
) {
1364
- let annotation = & mir . user_type_annotations [ annotation_index] ;
1365
+ let annotation = & self . user_type_annotations [ annotation_index] ;
1365
1366
span_mirbug ! (
1366
1367
self ,
1367
1368
stmt,
@@ -1420,7 +1421,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1420
1421
Locations :: All ( stmt. source_info . span ) ,
1421
1422
ConstraintCategory :: TypeAnnotation ,
1422
1423
) {
1423
- let annotation = & mir . user_type_annotations [ projection. base ] ;
1424
+ let annotation = & self . user_type_annotations [ projection. base ] ;
1424
1425
span_mirbug ! (
1425
1426
self ,
1426
1427
stmt,
@@ -2078,7 +2079,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
2078
2079
}
2079
2080
2080
2081
Rvalue :: Ref ( region, _borrow_kind, borrowed_place) => {
2081
- self . add_reborrow_constraint ( location, region, borrowed_place) ;
2082
+ self . add_reborrow_constraint ( mir , location, region, borrowed_place) ;
2082
2083
}
2083
2084
2084
2085
// FIXME: These other cases have to be implemented in future PRs
@@ -2177,6 +2178,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
2177
2178
/// - `borrowed_place`: the place `P` being borrowed
2178
2179
fn add_reborrow_constraint (
2179
2180
& mut self ,
2181
+ mir : & Mir < ' tcx > ,
2180
2182
location : Location ,
2181
2183
borrow_region : ty:: Region < ' tcx > ,
2182
2184
borrowed_place : & Place < ' tcx > ,
@@ -2226,7 +2228,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
2226
2228
match * elem {
2227
2229
ProjectionElem :: Deref => {
2228
2230
let tcx = self . infcx . tcx ;
2229
- let base_ty = base. ty ( self . mir , tcx) . to_ty ( tcx) ;
2231
+ let base_ty = base. ty ( mir, tcx) . to_ty ( tcx) ;
2230
2232
2231
2233
debug ! ( "add_reborrow_constraint - base_ty = {:?}" , base_ty) ;
2232
2234
match base_ty. sty {
0 commit comments