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`.
This commit is contained in:
parent
5f4e067719
commit
ca5525d564
169 changed files with 702 additions and 687 deletions
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue