diff options
| author | ouz-a <ouz.agz@gmail.com> | 2023-10-02 11:22:48 +0300 |
|---|---|---|
| committer | ouz-a <ouz.agz@gmail.com> | 2023-10-02 23:39:45 +0300 |
| commit | 5d753abb300eebfb6492dc2b47bd32052a322b71 (patch) | |
| tree | 2209d4af7e8fb773bbe592d11e2428a1c3f52bb6 /compiler/rustc_mir_transform/src | |
| parent | 6f0c5ee2d4c9ced0fa9d0e698b6a136cfdc51949 (diff) | |
| download | rust-5d753abb300eebfb6492dc2b47bd32052a322b71.tar.gz rust-5d753abb300eebfb6492dc2b47bd32052a322b71.zip | |
have better explanation for `relate_types`
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/add_subtyping_projections.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/compiler/rustc_mir_transform/src/add_subtyping_projections.rs b/compiler/rustc_mir_transform/src/add_subtyping_projections.rs index 594bb9bf142..1cc049d5a22 100644 --- a/compiler/rustc_mir_transform/src/add_subtyping_projections.rs +++ b/compiler/rustc_mir_transform/src/add_subtyping_projections.rs @@ -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 }; |
