diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-04-16 01:06:55 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-04-16 02:42:50 -0700 |
| commit | c98895d9f20eec10993bf2c3f07a2f2945228e49 (patch) | |
| tree | b1c752440e9426e5dbe210d473f28abdd4df559c /compiler/rustc_const_eval/src | |
| parent | 2a711152615ad9294dc0e5ee6885c8e9bb8418a9 (diff) | |
| download | rust-c98895d9f20eec10993bf2c3f07a2f2945228e49.tar.gz rust-c98895d9f20eec10993bf2c3f07a2f2945228e49.zip | |
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.
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/discriminant.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index 557e721249d..015a9beab83 100644 --- a/compiler/rustc_const_eval/src/interpret/discriminant.rs +++ b/compiler/rustc_const_eval/src/interpret/discriminant.rs @@ -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 } |
