have better explanation for relate_types
This commit is contained in:
parent
6f0c5ee2d4
commit
5d753abb30
13 changed files with 40 additions and 34 deletions
|
@ -24,24 +24,31 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
|
|||
rvalue: &mut Rvalue<'tcx>,
|
||||
location: Location,
|
||||
) {
|
||||
let place_ty = place.ty(self.local_decls, self.tcx);
|
||||
let mut place_ty = place.ty(self.local_decls, self.tcx).ty;
|
||||
let mut rval_ty = rvalue.ty(self.local_decls, self.tcx);
|
||||
if place_ty.ty != rval_ty {
|
||||
// Not erasing this causes `Free Regions` errors in validator,
|
||||
// when rval is `ReStatic`.
|
||||
rval_ty = self.tcx.erase_regions_ty(rval_ty);
|
||||
// Not erasing this causes `Free Regions` errors in validator,
|
||||
// when rval is `ReStatic`.
|
||||
rval_ty = self.tcx.erase_regions_ty(rval_ty);
|
||||
place_ty = self.tcx.erase_regions(place_ty);
|
||||
if place_ty != rval_ty {
|
||||
let temp = self
|
||||
.patcher
|
||||
.new_temp(rval_ty, self.local_decls[place.as_ref().local].source_info.span);
|
||||
let new_place = Place::from(temp);
|
||||
self.patcher.add_assign(location, new_place, rvalue.clone());
|
||||
let subtyped =
|
||||
new_place.project_deeper(&[ProjectionElem::Subtype(place_ty.ty)], self.tcx);
|
||||
let subtyped = new_place.project_deeper(&[ProjectionElem::Subtype(place_ty)], self.tcx);
|
||||
*rvalue = Rvalue::Use(Operand::Move(subtyped));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Aim here is to do this kind of transformation:
|
||||
//
|
||||
// let place: place_ty = rval;
|
||||
// // gets transformed to
|
||||
// let temp: rval_ty = rval;
|
||||
// let place: place_ty = temp as place_ty;
|
||||
//
|
||||
pub fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
let patch = MirPatch::new(body);
|
||||
let mut checker = SubTypeChecker { tcx, patcher: patch, local_decls: &body.local_decls };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue