about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-07-19 19:50:04 -0400
committerRalf Jung <post@ralfj.de>2022-07-20 17:12:07 -0400
commit5e840c5c8c75081dda4b33f8afcb0c77ad3105bb (patch)
tree04c4b2e6e9bb5210805b27ac89f990098b5e157c /compiler/rustc_const_eval/src/interpret
parent8affef2ccba424f37445f6df6592426600d00a31 (diff)
downloadrust-5e840c5c8c75081dda4b33f8afcb0c77ad3105bb.tar.gz
rust-5e840c5c8c75081dda4b33f8afcb0c77ad3105bb.zip
incorporate some review feedback
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
-rw-r--r--compiler/rustc_const_eval/src/interpret/cast.rs27
-rw-r--r--compiler/rustc_const_eval/src/interpret/memory.rs2
-rw-r--r--compiler/rustc_const_eval/src/interpret/traits.rs7
3 files changed, 8 insertions, 28 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs
index 473ba848a58..5d5c49c25a3 100644
--- a/compiler/rustc_const_eval/src/interpret/cast.rs
+++ b/compiler/rustc_const_eval/src/interpret/cast.rs
@@ -297,32 +297,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
                     Immediate::new_slice(ptr, length.eval_usize(*self.tcx, self.param_env), self);
                 self.write_immediate(val, dest)
             }
-            (&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => {
-                let val = self.read_immediate(src)?;
-                let (old_data, old_vptr) = val.to_scalar_pair()?;
+            (&ty::Dynamic(ref _data_a, ..), &ty::Dynamic(ref data_b, ..)) => {
+                let (old_data, old_vptr) = self.read_immediate(src)?.to_scalar_pair()?;
                 let old_vptr = self.scalar_to_ptr(old_vptr)?;
-                if data_a.principal_def_id() == data_b.principal_def_id() {
-                    return self.write_immediate(*val, dest);
-                }
-                // trait upcasting coercion
-                let Some(vptr_entry_idx) = self.tcx.vtable_trait_upcasting_coercion_new_vptr_slot((
-                    src_pointee_ty,
-                    dest_pointee_ty,
-                )) else {
-                    return self.write_immediate(*val, dest);
-                };
-
                 let (ty, _) = self.get_ptr_vtable(old_vptr)?;
-                let Some(ty::VtblEntry::TraitVPtr(new_trait)) = self.get_vtable_entries(old_vptr)?.get(vptr_entry_idx) else {
-                    throw_ub_format!(
-                        "upcasting to index {vptr_entry_idx} of vtable {old_vptr} but \
-                        that vtable is too small or does not have an upcast-vtable at that index"
-                    )
-                };
-                let new_trait = new_trait.map_bound(|trait_ref| {
-                    ty::ExistentialTraitRef::erase_self_ty(*self.tcx, trait_ref)
-                });
-                let new_vptr = self.get_vtable_ptr(ty, Some(new_trait))?;
+                let new_vptr = self.get_vtable_ptr(ty, data_b.principal())?;
                 self.write_immediate(Immediate::new_dyn_trait(old_data, new_vptr, self), dest)
             }
             (_, &ty::Dynamic(ref data, _)) => {
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs
index 5e49e6a4f08..b07530753c5 100644
--- a/compiler/rustc_const_eval/src/interpret/memory.rs
+++ b/compiler/rustc_const_eval/src/interpret/memory.rs
@@ -875,7 +875,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
                             write!(fmt, " (vtable: impl {trait_ref} for {ty})")?;
                         }
                         Some(GlobalAlloc::Vtable(ty, None)) => {
-                            write!(fmt, " (vtable: impl ? for {ty})")?;
+                            write!(fmt, " (vtable: impl <auto trait> for {ty})")?;
                         }
                         Some(GlobalAlloc::Static(did)) => {
                             write!(fmt, " (static: {})", self.ecx.tcx.def_path_str(did))?;
diff --git a/compiler/rustc_const_eval/src/interpret/traits.rs b/compiler/rustc_const_eval/src/interpret/traits.rs
index bddca2a20ed..b3a511d5a49 100644
--- a/compiler/rustc_const_eval/src/interpret/traits.rs
+++ b/compiler/rustc_const_eval/src/interpret/traits.rs
@@ -10,9 +10,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
     /// Creates a dynamic vtable for the given type and vtable origin. This is used only for
     /// objects.
     ///
-    /// The `trait_ref` encodes the erased self type. Hence, if we are
-    /// making an object `Foo<Trait>` from a value of type `Foo<T>`, then
-    /// `trait_ref` would map `T: Trait`.
+    /// The `trait_ref` encodes the erased self type. Hence, if we are making an object `Foo<Trait>`
+    /// from a value of type `Foo<T>`, then `trait_ref` would map `T: Trait`. `None` here means that
+    /// this is an auto trait without any methods, so we only need the basic vtable (drop, size,
+    /// align).
     pub fn get_vtable_ptr(
         &self,
         ty: Ty<'tcx>,