Skip to content

Commit

Permalink
Rollup merge of rust-lang#115798 - RalfJung:non_1zst_field, r=wesleyw…
Browse files Browse the repository at this point in the history
…iser

add helper method for finding the one non-1-ZST field
  • Loading branch information
matthiaskrgr authored Sep 13, 2023
2 parents 9475cdb + 72fb4b8 commit 1956fb8
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,12 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
) -> (Pointer, Value) {
let (ptr, vtable) = 'block: {
if let Abi::Scalar(_) = arg.layout().abi {
'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() {
for i in 0..arg.layout().fields.count() {
let field = arg.value_field(fx, FieldIdx::new(i));
if !field.layout().is_1zst() {
// we found the one non-1-ZST field that is allowed
// now find *its* non-zero-sized field, or stop if it's a
// pointer
arg = field;
continue 'descend_newtypes;
}
}

bug!("receiver has no non-zero-sized fields {:?}", arg);
while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() {
let (idx, _) = arg
.layout()
.non_1zst_field(fx)
.expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type");
arg = arg.value_field(fx, FieldIdx::new(idx));
}
}

Expand Down

0 comments on commit 1956fb8

Please sign in to comment.