@@ -24,24 +24,31 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
24
24
rvalue : & mut Rvalue < ' tcx > ,
25
25
location : Location ,
26
26
) {
27
- let place_ty = place. ty ( self . local_decls , self . tcx ) ;
27
+ let mut place_ty = place. ty ( self . local_decls , self . tcx ) . ty ;
28
28
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 {
33
34
let temp = self
34
35
. patcher
35
36
. new_temp ( rval_ty, self . local_decls [ place. as_ref ( ) . local ] . source_info . span ) ;
36
37
let new_place = Place :: from ( temp) ;
37
38
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 ) ;
40
40
* rvalue = Rvalue :: Use ( Operand :: Move ( subtyped) ) ;
41
41
}
42
42
}
43
43
}
44
44
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
+ //
45
52
pub fn subtype_finder < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
46
53
let patch = MirPatch :: new ( body) ;
47
54
let mut checker = SubTypeChecker { tcx, patcher : patch, local_decls : & body. local_decls } ;
0 commit comments