From ca5525d5643f4eb7de5c5e69d0691fc8f1cacfca Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 5 Mar 2022 07:28:41 +1100 Subject: Improve `AdtDef` interning. This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`. --- compiler/rustc_const_eval/src/const_eval/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_const_eval/src/const_eval') diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs index c49c5ecac26..6fd7f707e7e 100644 --- a/compiler/rustc_const_eval/src/const_eval/mod.rs +++ b/compiler/rustc_const_eval/src/const_eval/mod.rs @@ -105,13 +105,13 @@ fn const_to_valtree_inner<'tcx>( ty::Array(_, len) => branches(usize::try_from(len.eval_usize(ecx.tcx.tcx, ecx.param_env)).unwrap(), None), ty::Adt(def, _) => { - if def.variants.is_empty() { + if def.variants().is_empty() { bug!("uninhabited types should have errored and never gotten converted to valtree") } let variant = ecx.read_discriminant(&place.into()).unwrap().1; - branches(def.variants[variant].fields.len(), def.is_enum().then_some(variant)) + branches(def.variant(variant).fields.len(), def.is_enum().then_some(variant)) } ty::Never @@ -150,11 +150,11 @@ pub(crate) fn try_destructure_const<'tcx>( // Checks if we have any variants, to avoid downcasting to a non-existing variant (when // there are no variants `read_discriminant` successfully returns a non-existing variant // index). - ty::Adt(def, _) if def.variants.is_empty() => throw_ub!(Unreachable), + ty::Adt(def, _) if def.variants().is_empty() => throw_ub!(Unreachable), ty::Adt(def, _) => { let variant = ecx.read_discriminant(&op)?.1; let down = ecx.operand_downcast(&op, variant)?; - (def.variants[variant].fields.len(), Some(variant), down) + (def.variant(variant).fields.len(), Some(variant), down) } ty::Tuple(substs) => (substs.len(), None, op), _ => bug!("cannot destructure constant {:?}", val), -- cgit 1.4.1-3-g733a5