diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-09-13 18:37:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-13 18:37:42 +0200 |
| commit | 565b9c22645caa647e6b59032fc38d85db5ab254 (patch) | |
| tree | e357a87a1bf7c09505f285397f60b33402567da1 /compiler/rustc_codegen_cranelift | |
| parent | 1ec29fb24f7222ed7448209534895e708ac243fc (diff) | |
| parent | 60091fe92403f5a4aca1d273295668b546bf2bf2 (diff) | |
| download | rust-565b9c22645caa647e6b59032fc38d85db5ab254.tar.gz rust-565b9c22645caa647e6b59032fc38d85db5ab254.zip | |
Rollup merge of #115798 - RalfJung:non_1zst_field, r=wesleywiser
add helper method for finding the one non-1-ZST field
Diffstat (limited to 'compiler/rustc_codegen_cranelift')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/vtable.rs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/vtable.rs b/compiler/rustc_codegen_cranelift/src/vtable.rs index 7598c6eee03..41ea0b122de 100644 --- a/compiler/rustc_codegen_cranelift/src/vtable.rs +++ b/compiler/rustc_codegen_cranelift/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)); } } |
