about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2023-04-16 01:06:55 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2023-04-16 02:42:50 -0700
commitc98895d9f20eec10993bf2c3f07a2f2945228e49 (patch)
treeb1c752440e9426e5dbe210d473f28abdd4df559c /compiler/rustc_const_eval/src
parent2a711152615ad9294dc0e5ee6885c8e9bb8418a9 (diff)
downloadrust-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.rs17
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
                         }