Skip to content

Commit 059b589

Browse files
committed
Implement dynamic dispatch for self: Box<T>
1 parent f78c99e commit 059b589

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/vtable.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ pub fn get_ptr_and_method_ref<'a, 'tcx: 'a>(
3737
arg: CValue<'tcx>,
3838
idx: usize,
3939
) -> (Value, Value) {
40+
let arg = if arg.layout().ty.is_box() {
41+
// Cast `Box<T>` to `*mut T` so `load_value_pair` works
42+
arg.unchecked_cast_to(fx.layout_of(fx.tcx.mk_mut_ptr(arg.layout().ty.boxed_ty())))
43+
} else {
44+
arg
45+
};
46+
4047
let (ptr, vtable) = arg.load_value_pair(fx);
4148
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes();
4249
let func_ref = fx.bcx.ins().load(

0 commit comments

Comments
 (0)