Skip to content

Commit 12ec2f0

Browse files
compiler-errorseholk
authored andcommitted
Construct dyn* during const interp
1 parent 12353c1 commit 12ec2f0

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
907907
llargs.push(data_ptr);
908908
continue;
909909
}
910-
_ => span_bug!(span, "can't codegen a virtual call on {:?}", op),
910+
_ => span_bug!(span, "can't codegen a virtual call on {:#?}", op),
911911
}
912912
}
913913

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
110110
}
111111

112112
DynStar => {
113-
unimplemented!()
113+
if let ty::Dynamic(data, _, ty::TraitObjectRepresentation::Sized) = cast_ty.kind() {
114+
// Initial cast from sized to dyn trait
115+
let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?;
116+
let ptr = self.read_immediate(src)?.to_scalar();
117+
// FIXME(dyn-star): This should not use new_dyn_trait, but
118+
// it does exactly the same thing (makes a scalar pair)...
119+
// so maybe we should just duplicate/rename the function.
120+
let val = Immediate::new_dyn_trait(ptr, vtable, &*self.tcx);
121+
self.write_immediate(val, dest)?;
122+
} else {
123+
bug!()
124+
}
114125
}
115126
}
116127
Ok(())

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,15 +2545,9 @@ where
25452545
}
25462546
}
25472547

2548-
// dyn*
2548+
// dyn* (both fields are usize-sized)
25492549
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => {
2550-
TyMaybeWithLayout::TyAndLayout(
2551-
tcx.layout_of(
2552-
ty::ParamEnv::reveal_all()
2553-
.and(tcx.mk_tup([tcx.types.usize, tcx.types.usize].into_iter())),
2554-
)
2555-
.unwrap(),
2556-
)
2550+
TyMaybeWithLayout::Ty(tcx.types.usize)
25572551
}
25582552

25592553
ty::Projection(_)

src/test/ui/async-await/dyn-star-trait-const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
2-
// ignore-test
32
#![feature(async_fn_in_traits)]
3+
#![allow(unused)]
44

55
use std::fmt::Debug;
66

0 commit comments

Comments
 (0)