@@ -39,7 +39,8 @@ use rustc::ty::fold::TypeFoldable;
39
39
use rustc:: ty:: subst:: { Subst , Substs , 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 ;
@@ -1360,7 +1361,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1360
1361
location. to_locations ( ) ,
1361
1362
ConstraintCategory :: Boring ,
1362
1363
) {
1363
- let annotation = & mir . user_type_annotations [ annotation_index] ;
1364
+ let annotation = & self . user_type_annotations [ annotation_index] ;
1364
1365
span_mirbug ! (
1365
1366
self ,
1366
1367
stmt,
@@ -1419,7 +1420,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1419
1420
Locations :: All ( stmt. source_info . span ) ,
1420
1421
ConstraintCategory :: TypeAnnotation ,
1421
1422
) {
1422
- let annotation = & mir . user_type_annotations [ projection. base ] ;
1423
+ let annotation = & self . user_type_annotations [ projection. base ] ;
1423
1424
span_mirbug ! (
1424
1425
self ,
1425
1426
stmt,
@@ -2069,7 +2070,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
2069
2070
}
2070
2071
2071
2072
Rvalue :: Ref ( region, _borrow_kind, borrowed_place) => {
2072
- self . add_reborrow_constraint ( location, region, borrowed_place) ;
2073
+ self . add_reborrow_constraint ( mir , location, region, borrowed_place) ;
2073
2074
}
2074
2075
2075
2076
// FIXME: These other cases have to be implemented in future PRs
@@ -2168,6 +2169,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
2168
2169
/// - `borrowed_place`: the place `P` being borrowed
2169
2170
fn add_reborrow_constraint (
2170
2171
& mut self ,
2172
+ mir : & Mir < ' tcx > ,
2171
2173
location : Location ,
2172
2174
borrow_region : ty:: Region < ' tcx > ,
2173
2175
borrowed_place : & Place < ' tcx > ,
@@ -2217,7 +2219,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
2217
2219
match * elem {
2218
2220
ProjectionElem :: Deref => {
2219
2221
let tcx = self . infcx . tcx ;
2220
- let base_ty = base. ty ( self . mir , tcx) . to_ty ( tcx) ;
2222
+ let base_ty = base. ty ( mir, tcx) . to_ty ( tcx) ;
2221
2223
2222
2224
debug ! ( "add_reborrow_constraint - base_ty = {:?}" , base_ty) ;
2223
2225
match base_ty. sty {
0 commit comments