Remove unchecked_cast_to

This commit is contained in:
bjorn3 2020-03-29 11:52:30 +02:00
parent 3ef6170142
commit ea1a99900e
2 changed files with 11 additions and 12 deletions

View File

@ -485,7 +485,7 @@ fn trans_stmt<'tcx>(
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
let operand = trans_operand(fx, operand);
lval.write_cvalue(fx, operand.unchecked_cast_to(to_layout));
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
}
Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
let operand = trans_operand(fx, operand);
@ -509,7 +509,7 @@ fn trans_stmt<'tcx>(
if is_fat_ptr(fx, from_ty) {
if is_fat_ptr(fx, to_ty) {
// fat-ptr -> fat-ptr
lval.write_cvalue(fx, operand.unchecked_cast_to(dest_layout));
lval.write_cvalue(fx, operand.cast_pointer_to(dest_layout));
} else {
// fat-ptr -> thin-ptr
let (ptr, _extra) = operand.load_scalar_pair(fx);

View File

@ -243,7 +243,10 @@ impl<'tcx> CValue<'tcx> {
CValue::by_val(val, layout)
}
pub(crate) fn unchecked_cast_to(self, layout: TyAndLayout<'tcx>) -> Self {
pub(crate) fn cast_pointer_to(self, layout: TyAndLayout<'tcx>) -> Self {
assert!(matches!(self.layout().ty.kind, ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)));
assert!(matches!(layout.ty.kind, ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)));
assert_eq!(self.layout().abi, layout.abi);
CValue(self.0, layout)
}
}
@ -560,20 +563,16 @@ impl<'tcx> CPlace<'tcx> {
}
}
pub(crate) fn unchecked_cast_to(self, layout: TyAndLayout<'tcx>) -> Self {
assert!(!self.layout().is_unsized());
CPlace {
inner: self.inner,
layout,
}
}
pub(crate) fn downcast_variant(
self,
fx: &FunctionCx<'_, 'tcx, impl Backend>,
variant: VariantIdx,
) -> Self {
assert!(!self.layout().is_unsized());
let layout = self.layout().for_variant(fx, variant);
self.unchecked_cast_to(layout)
CPlace {
inner: self.inner,
layout,
}
}
}