Skip to content

Commit 5d593cf

Browse files
committed
Return FieldIdx from non_1zst_field
1 parent 322e92b commit 5d593cf

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

compiler/rustc_codegen_cranelift/src/vtable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
5353
.layout()
5454
.non_1zst_field(fx)
5555
.expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type");
56-
arg = arg.value_field(fx, FieldIdx::new(idx));
56+
arg = arg.value_field(fx, idx);
5757
}
5858
}
5959

compiler/rustc_codegen_ssa/src/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10191019
let (idx, _) = op.layout.non_1zst_field(bx).expect(
10201020
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
10211021
);
1022-
op = op.extract_field(bx, idx);
1022+
op = op.extract_field(bx, idx.as_usize());
10231023
}
10241024

10251025
// now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
@@ -1051,7 +1051,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10511051
let (idx, _) = op.layout.non_1zst_field(bx).expect(
10521052
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
10531053
);
1054-
op = op.extract_field(bx, idx);
1054+
op = op.extract_field(bx, idx.as_usize());
10551055
}
10561056

10571057
// Make sure that we've actually unwrapped the rcvr down

compiler/rustc_const_eval/src/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
793793
let (idx, _) = receiver.layout.non_1zst_field(self).expect(
794794
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
795795
);
796-
receiver = self.project_field(&receiver, idx)?;
796+
receiver = self.project_field(&receiver, idx.as_usize())?;
797797
}
798798
}
799799
};

compiler/rustc_target/src/abi/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
279279

280280
/// Finds the one field that is not a 1-ZST.
281281
/// Returns `None` if there are multiple non-1-ZST fields or only 1-ZST-fields.
282-
pub fn non_1zst_field<C>(&self, cx: &C) -> Option<(usize, Self)>
282+
pub fn non_1zst_field<C>(&self, cx: &C) -> Option<(FieldIdx, Self)>
283283
where
284284
Ty: TyAbiInterface<'a, C> + Copy,
285285
{
@@ -293,8 +293,12 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
293293
// More than one non-1-ZST field.
294294
return None;
295295
}
296-
found = Some((field_idx, field));
296+
297+
// Arrays are the only things with more than FieldIdx::MAX fields,
298+
// but only 1-element arrays can ever return non-None here.
299+
found = Some((FieldIdx::from_usize(field_idx), field));
297300
}
301+
298302
found
299303
}
300304
}

0 commit comments

Comments
 (0)