@@ -24,24 +24,31 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
2424 rvalue : & mut Rvalue < ' tcx > ,
2525 location : Location ,
2626 ) {
27- let place_ty = place. ty ( self . local_decls , self . tcx ) ;
27+ let mut place_ty = place. ty ( self . local_decls , self . tcx ) . ty ;
2828 let mut rval_ty = rvalue. ty ( self . local_decls , self . tcx ) ;
29- if place_ty. ty != rval_ty {
30- // Not erasing this causes `Free Regions` errors in validator,
31- // when rval is `ReStatic`.
32- rval_ty = self . tcx . erase_regions_ty ( rval_ty) ;
29+ // Not erasing this causes `Free Regions` errors in validator,
30+ // when rval is `ReStatic`.
31+ rval_ty = self . tcx . erase_regions_ty ( rval_ty) ;
32+ place_ty = self . tcx . erase_regions ( place_ty) ;
33+ if place_ty != rval_ty {
3334 let temp = self
3435 . patcher
3536 . new_temp ( rval_ty, self . local_decls [ place. as_ref ( ) . local ] . source_info . span ) ;
3637 let new_place = Place :: from ( temp) ;
3738 self . patcher . add_assign ( location, new_place, rvalue. clone ( ) ) ;
38- let subtyped =
39- new_place. project_deeper ( & [ ProjectionElem :: Subtype ( place_ty. ty ) ] , self . tcx ) ;
39+ let subtyped = new_place. project_deeper ( & [ ProjectionElem :: Subtype ( place_ty) ] , self . tcx ) ;
4040 * rvalue = Rvalue :: Use ( Operand :: Move ( subtyped) ) ;
4141 }
4242 }
4343}
4444
45+ // Aim here is to do this kind of transformation:
46+ //
47+ // let place: place_ty = rval;
48+ // // gets transformed to
49+ // let temp: rval_ty = rval;
50+ // let place: place_ty = temp as place_ty;
51+ //
4552pub fn subtype_finder < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
4653 let patch = MirPatch :: new ( body) ;
4754 let mut checker = SubTypeChecker { tcx, patcher : patch, local_decls : & body. local_decls } ;
0 commit comments