Skip to content

Commit ef6df7e

Browse files
committed
Handle wrappers around dyn* in receiver types
Fixes rust-lang#1324
1 parent 9e6dfba commit ef6df7e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

scripts/test_rustc_tests.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ rm tests/ui/simd/intrinsic/generic-reduction-pass.rs # simd_reduce_add_unordered
113113
rm tests/ui/simd/intrinsic/generic-as.rs # crash when accessing vector type filed (#1318)
114114
rm tests/ui/simd/simd-bitmask.rs # crash
115115

116-
rm tests/ui/dyn-star/dispatch-on-pin-mut.rs
117-
118116
# bugs in the test suite
119117
# ======================
120118
rm tests/ui/backtrace.rs # TODO warning

src/vtable.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,29 @@ pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -
4343

4444
pub(crate) fn get_ptr_and_method_ref<'tcx>(
4545
fx: &mut FunctionCx<'_, '_, 'tcx>,
46-
arg: CValue<'tcx>,
46+
mut arg: CValue<'tcx>,
4747
idx: usize,
4848
) -> (Pointer, Value) {
4949
let (ptr, vtable) = 'block: {
50+
if let Abi::Scalar(_) = arg.layout().abi {
51+
'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr()
52+
&& !arg.layout().ty.is_region_ptr()
53+
{
54+
for i in 0..arg.layout().fields.count() {
55+
let field = arg.value_field(fx, mir::Field::new(i));
56+
if !field.layout().is_zst() {
57+
// we found the one non-zero-sized field that is allowed
58+
// now find *its* non-zero-sized field, or stop if it's a
59+
// pointer
60+
arg = field;
61+
continue 'descend_newtypes;
62+
}
63+
}
64+
65+
bug!("receiver has no non-zero-sized fields {:?}", arg);
66+
}
67+
}
68+
5069
if let ty::Ref(_, ty, _) = arg.layout().ty.kind() {
5170
if ty.is_dyn_star() {
5271
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap().ty);

0 commit comments

Comments
 (0)