1
Fork 0

be even more precise about "cast" vs "coercion"

This commit is contained in:
Lukas Markeffsky 2024-09-15 19:35:06 +02:00
parent 5e60d1f87e
commit bd31e3ed70
90 changed files with 291 additions and 233 deletions

View file

@ -440,6 +440,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
| PointerCoercion::UnsafeFnPointer
| PointerCoercion::ClosureFnPointer(_)
| PointerCoercion::ReifyFnPointer,
_,
),
_,
_,
@ -448,7 +449,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
}
Rvalue::Cast(
CastKind::PointerCoercion(PointerCoercion::Unsize | PointerCoercion::DynStar),
CastKind::PointerCoercion(PointerCoercion::Unsize | PointerCoercion::DynStar, _),
_,
_,
) => {

View file

@ -32,7 +32,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
if cast_ty == dest.layout.ty { dest.layout } else { self.layout_of(cast_ty)? };
// FIXME: In which cases should we trigger UB when the source is uninit?
match cast_kind {
CastKind::PointerCoercion(PointerCoercion::Unsize) => {
CastKind::PointerCoercion(PointerCoercion::Unsize, _) => {
self.unsize_into(src, cast_layout, dest)?;
}
@ -68,11 +68,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
_,
) => {
bug!("{cast_kind:?} casts are for borrowck only, not runtime MIR");
}
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer) => {
CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer, _) => {
// All reifications must be monomorphic, bail out otherwise.
ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
@ -94,7 +95,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
}
CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer) => {
CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer, _) => {
let src = self.read_immediate(src)?;
match cast_ty.kind() {
ty::FnPtr(..) => {
@ -105,7 +106,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
}
CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_)) => {
CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_), _) => {
// All reifications must be monomorphic, bail out otherwise.
ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
@ -125,7 +126,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
}
CastKind::PointerCoercion(PointerCoercion::DynStar) => {
CastKind::PointerCoercion(PointerCoercion::DynStar, _) => {
if let ty::Dynamic(data, _, ty::DynStar) = cast_ty.kind() {
// Initial cast from sized to dyn trait
let vtable = self.get_vtable_ptr(src.layout.ty, data)?;