1
Fork 0

Rollup merge of #110394 - scottmcm:less-idx-new, r=WaffleLapkin

Various minor Idx-related tweaks

Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify.

cc https://github.com/rust-lang/compiler-team/issues/606
r? `@WaffleLapkin`
This commit is contained in:
Matthias Krüger 2023-04-17 18:13:35 +02:00 committed by GitHub
commit 0790996a07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 55 additions and 52 deletions

View file

@ -211,18 +211,19 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let variant_index_relative = u32::try_from(variant_index_relative)
.expect("we checked that this fits into a u32");
// Then computing the absolute variant idx should not overflow any more.
let variant_index = variants_start
.checked_add(variant_index_relative)
.expect("overflow computing absolute variant idx");
let variants_len = op
let variant_index = VariantIdx::from_u32(
variants_start
.checked_add(variant_index_relative)
.expect("overflow computing absolute variant idx"),
);
let variants = op
.layout
.ty
.ty_adt_def()
.expect("tagged layout for non adt")
.variants()
.len();
assert!(usize::try_from(variant_index).unwrap() < variants_len);
VariantIdx::from_u32(variant_index)
.variants();
assert!(variant_index < variants.next_index());
variant_index
} else {
untagged_variant
}