diff options
| author | Ralf Jung <post@ralfj.de> | 2023-09-12 20:51:00 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-09-12 20:52:05 +0200 |
| commit | 72fb4b8f3160751af92185d4a454a09884a90b81 (patch) | |
| tree | a6032d56619cc6babab82933111bb13b32420278 | |
| parent | c41e7794cd4acf979204d7f68aca74b828a389b2 (diff) | |
| download | rust-72fb4b8f3160751af92185d4a454a09884a90b81.tar.gz rust-72fb4b8f3160751af92185d4a454a09884a90b81.zip | |
add helper method for finding the one non-1-ZST field
| -rw-r--r-- | src/vtable.rs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/vtable.rs b/src/vtable.rs index 7598c6eee03..41ea0b122de 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -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)); } } |
