summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_const_eval/src/interpret/cast.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /compiler/rustc_const_eval/src/interpret/cast.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/cast.rs')
-rw-r--r--compiler/rustc_const_eval/src/interpret/cast.rs51
1 files changed, 38 insertions, 13 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs
index 2be5ed896..163e3f869 100644
--- a/compiler/rustc_const_eval/src/interpret/cast.rs
+++ b/compiler/rustc_const_eval/src/interpret/cast.rs
@@ -67,12 +67,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
Pointer(PointerCast::ReifyFnPointer) => {
+ // All reifications must be monomorphic, bail out otherwise.
+ ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
+
// The src operand does not matter, just its type
match *src.layout.ty.kind() {
ty::FnDef(def_id, substs) => {
- // All reifications must be monomorphic, bail out otherwise.
- ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
-
let instance = ty::Instance::resolve_for_fn_ptr(
*self.tcx,
self.param_env,
@@ -100,12 +100,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
Pointer(PointerCast::ClosureFnPointer(_)) => {
+ // All reifications must be monomorphic, bail out otherwise.
+ ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
+
// The src operand does not matter, just its type
match *src.layout.ty.kind() {
ty::Closure(def_id, substs) => {
- // All reifications must be monomorphic, bail out otherwise.
- ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
-
let instance = ty::Instance::resolve_closure(
*self.tcx,
def_id,
@@ -133,6 +133,22 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
bug!()
}
}
+
+ Transmute => {
+ assert!(src.layout.is_sized());
+ assert!(dest.layout.is_sized());
+ if src.layout.size != dest.layout.size {
+ throw_ub_format!(
+ "transmuting from {}-byte type to {}-byte type: `{}` -> `{}`",
+ src.layout.size.bytes(),
+ dest.layout.size.bytes(),
+ src.layout.ty,
+ dest.layout.ty,
+ );
+ }
+
+ self.copy_op(src, dest, /*allow_transmute*/ true)?;
+ }
}
Ok(())
}
@@ -359,8 +375,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let val = Immediate::new_dyn_trait(ptr, vtable, &*self.tcx);
self.write_immediate(val, dest)
}
-
_ => {
+ // Do not ICE if we are not monomorphic enough.
+ ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
+ ensure_monomorphic_enough(*self.tcx, cast_ty)?;
+
span_bug!(
self.cur_span(),
"invalid pointer unsizing {:?} -> {:?}",
@@ -404,12 +423,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
Ok(())
}
- _ => span_bug!(
- self.cur_span(),
- "unsize_into: invalid conversion: {:?} -> {:?}",
- src.layout,
- dest.layout
- ),
+ _ => {
+ // Do not ICE if we are not monomorphic enough.
+ ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
+ ensure_monomorphic_enough(*self.tcx, cast_ty.ty)?;
+
+ span_bug!(
+ self.cur_span(),
+ "unsize_into: invalid conversion: {:?} -> {:?}",
+ src.layout,
+ dest.layout
+ )
+ }
}
}
}