Rollup merge of #115798 - RalfJung:non_1zst_field, r=wesleywiser

add helper method for finding the one non-1-ZST field
This commit is contained in:
Matthias Krüger 2023-09-13 18:37:42 +02:00 committed by GitHub
commit 1956fb84f3

View File

@ -48,19 +48,12 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
) -> (Pointer, Value) { ) -> (Pointer, Value) {
let (ptr, vtable) = 'block: { let (ptr, vtable) = 'block: {
if let Abi::Scalar(_) = arg.layout().abi { if let Abi::Scalar(_) = arg.layout().abi {
'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() { while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() {
for i in 0..arg.layout().fields.count() { let (idx, _) = arg
let field = arg.value_field(fx, FieldIdx::new(i)); .layout()
if !field.layout().is_1zst() { .non_1zst_field(fx)
// we found the one non-1-ZST field that is allowed .expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type");
// now find *its* non-zero-sized field, or stop if it's a arg = arg.value_field(fx, FieldIdx::new(idx));
// pointer
arg = field;
continue 'descend_newtypes;
}
}
bug!("receiver has no non-zero-sized fields {:?}", arg);
} }
} }