From 12ec2f0e34e230a5d95d7ef06c6de92efcdcbedf Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 29 Aug 2022 03:24:30 +0000 Subject: Construct dyn* during const interp --- compiler/rustc_const_eval/src/interpret/cast.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_const_eval/src/interpret') 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(()) -- cgit 1.4.1-3-g733a5