about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-08-29 03:24:30 +0000
committerEric Holk <ericholk@microsoft.com>2022-09-12 16:55:59 -0700
commit12ec2f0e34e230a5d95d7ef06c6de92efcdcbedf (patch)
tree9473b38dfac7be6716b52e839d3182dacf72cb04 /compiler
parent12353c11ca2848c15511d3b3d400fca412daff7b (diff)
downloadrust-12ec2f0e34e230a5d95d7ef06c6de92efcdcbedf.tar.gz
rust-12ec2f0e34e230a5d95d7ef06c6de92efcdcbedf.zip
Construct dyn* during const interp
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/block.rs2
-rw-r--r--compiler/rustc_const_eval/src/interpret/cast.rs13
-rw-r--r--compiler/rustc_middle/src/ty/layout.rs10
3 files changed, 15 insertions, 10 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs
index 438bb133fd1..0c7cd43eb27 100644
--- a/compiler/rustc_codegen_ssa/src/mir/block.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/block.rs
@@ -907,7 +907,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                         llargs.push(data_ptr);
                         continue;
                     }
-                    _ => span_bug!(span, "can't codegen a virtual call on {:?}", op),
+                    _ => span_bug!(span, "can't codegen a virtual call on {:#?}", op),
                 }
             }
 
diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs
index 9beeb2d8b2c..6831e53d014 100644
--- a/compiler/rustc_const_eval/src/interpret/cast.rs
+++ b/compiler/rustc_const_eval/src/interpret/cast.rs
@@ -110,7 +110,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
             }
 
             DynStar => {
-                unimplemented!()
+                if let ty::Dynamic(data, _, ty::TraitObjectRepresentation::Sized) = cast_ty.kind() {
+                    // Initial cast from sized to dyn trait
+                    let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?;
+                    let ptr = self.read_immediate(src)?.to_scalar();
+                    // FIXME(dyn-star): This should not use new_dyn_trait, but
+                    // it does exactly the same thing (makes a scalar pair)...
+                    // so maybe we should just duplicate/rename the function.
+                    let val = Immediate::new_dyn_trait(ptr, vtable, &*self.tcx);
+                    self.write_immediate(val, dest)?;
+                } else {
+                    bug!()
+                }
             }
         }
         Ok(())
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index 240bead5494..c0d21250c30 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -2545,15 +2545,9 @@ where
                     }
                 }
 
-                // dyn*
+                // dyn* (both fields are usize-sized)
                 ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => {
-                    TyMaybeWithLayout::TyAndLayout(
-                        tcx.layout_of(
-                            ty::ParamEnv::reveal_all()
-                                .and(tcx.mk_tup([tcx.types.usize, tcx.types.usize].into_iter())),
-                        )
-                        .unwrap(),
-                    )
+                    TyMaybeWithLayout::Ty(tcx.types.usize)
                 }
 
                 ty::Projection(_)