Skip to content

Commit ea1a999

Browse files
committed
Remove unchecked_cast_to
1 parent 3ef6170 commit ea1a999

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn trans_stmt<'tcx>(
485485
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
486486
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
487487
let operand = trans_operand(fx, operand);
488-
lval.write_cvalue(fx, operand.unchecked_cast_to(to_layout));
488+
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
489489
}
490490
Rvalue::Cast(CastKind::Misc, operand, to_ty) => {
491491
let operand = trans_operand(fx, operand);
@@ -509,7 +509,7 @@ fn trans_stmt<'tcx>(
509509
if is_fat_ptr(fx, from_ty) {
510510
if is_fat_ptr(fx, to_ty) {
511511
// fat-ptr -> fat-ptr
512-
lval.write_cvalue(fx, operand.unchecked_cast_to(dest_layout));
512+
lval.write_cvalue(fx, operand.cast_pointer_to(dest_layout));
513513
} else {
514514
// fat-ptr -> thin-ptr
515515
let (ptr, _extra) = operand.load_scalar_pair(fx);

src/value_and_place.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ impl<'tcx> CValue<'tcx> {
243243
CValue::by_val(val, layout)
244244
}
245245

246-
pub(crate) fn unchecked_cast_to(self, layout: TyAndLayout<'tcx>) -> Self {
246+
pub(crate) fn cast_pointer_to(self, layout: TyAndLayout<'tcx>) -> Self {
247+
assert!(matches!(self.layout().ty.kind, ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)));
248+
assert!(matches!(layout.ty.kind, ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)));
249+
assert_eq!(self.layout().abi, layout.abi);
247250
CValue(self.0, layout)
248251
}
249252
}
@@ -560,20 +563,16 @@ impl<'tcx> CPlace<'tcx> {
560563
}
561564
}
562565

563-
pub(crate) fn unchecked_cast_to(self, layout: TyAndLayout<'tcx>) -> Self {
564-
assert!(!self.layout().is_unsized());
565-
CPlace {
566-
inner: self.inner,
567-
layout,
568-
}
569-
}
570-
571566
pub(crate) fn downcast_variant(
572567
self,
573568
fx: &FunctionCx<'_, 'tcx, impl Backend>,
574569
variant: VariantIdx,
575570
) -> Self {
571+
assert!(!self.layout().is_unsized());
576572
let layout = self.layout().for_variant(fx, variant);
577-
self.unchecked_cast_to(layout)
573+
CPlace {
574+
inner: self.inner,
575+
layout,
576+
}
578577
}
579578
}

0 commit comments

Comments
 (0)