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
|
@ -138,7 +138,7 @@ impl BorrowExplanation {
|
|||
let mut ty = local_decl.ty;
|
||||
if local_decl.source_info.span.desugaring_kind() == Some(DesugaringKind::ForLoop) {
|
||||
if let ty::Adt(adt, substs) = local_decl.ty.kind() {
|
||||
if tcx.is_diagnostic_item(sym::Option, adt.did) {
|
||||
if tcx.is_diagnostic_item(sym::Option, adt.did()) {
|
||||
// in for loop desugaring, only look at the `Some(..)` inner type
|
||||
ty = substs.type_at(0);
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ impl BorrowExplanation {
|
|||
// If type is an ADT that implements Drop, then
|
||||
// simplify output by reporting just the ADT name.
|
||||
ty::Adt(adt, _substs) if adt.has_dtor(tcx) && !adt.is_box() => {
|
||||
("`Drop` code", format!("type `{}`", tcx.def_path_str(adt.did)))
|
||||
("`Drop` code", format!("type `{}`", tcx.def_path_str(adt.did())))
|
||||
}
|
||||
|
||||
// Otherwise, just report the whole type (and use
|
||||
|
|
|
@ -370,7 +370,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
ty::Adt(def, _) => {
|
||||
let variant = if let Some(idx) = variant_index {
|
||||
assert!(def.is_enum());
|
||||
&def.variants[idx]
|
||||
&def.variant(idx)
|
||||
} else {
|
||||
def.non_enum_variant()
|
||||
};
|
||||
|
@ -701,7 +701,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
|
|||
BorrowedContentSource::DerefMutableRef => "a mutable reference".to_string(),
|
||||
BorrowedContentSource::OverloadedDeref(ty) => ty
|
||||
.ty_adt_def()
|
||||
.and_then(|adt| match tcx.get_diagnostic_name(adt.did)? {
|
||||
.and_then(|adt| match tcx.get_diagnostic_name(adt.did())? {
|
||||
name @ (sym::Rc | sym::Arc) => Some(format!("an `{}`", name)),
|
||||
_ => None,
|
||||
})
|
||||
|
@ -731,7 +731,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
|
|||
}
|
||||
BorrowedContentSource::OverloadedDeref(ty) => ty
|
||||
.ty_adt_def()
|
||||
.and_then(|adt| match tcx.get_diagnostic_name(adt.did)? {
|
||||
.and_then(|adt| match tcx.get_diagnostic_name(adt.did())? {
|
||||
name @ (sym::Rc | sym::Arc) => Some(format!("an `{}`", name)),
|
||||
_ => None,
|
||||
})
|
||||
|
|
|
@ -388,7 +388,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
};
|
||||
let ty = move_place.ty(self.body, self.infcx.tcx).ty;
|
||||
let def_id = match *ty.kind() {
|
||||
ty::Adt(self_def, _) => self_def.did,
|
||||
ty::Adt(self_def, _) => self_def.did(),
|
||||
ty::Foreign(def_id)
|
||||
| ty::FnDef(def_id, _)
|
||||
| ty::Closure(def_id, _)
|
||||
|
|
|
@ -345,8 +345,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
ty::Adt(adt, substs) => {
|
||||
let generic_arg = substs[param_index as usize];
|
||||
let identity_substs =
|
||||
InternalSubsts::identity_for_item(self.infcx.tcx, adt.did);
|
||||
let base_ty = self.infcx.tcx.mk_adt(adt, identity_substs);
|
||||
InternalSubsts::identity_for_item(self.infcx.tcx, adt.did());
|
||||
let base_ty = self.infcx.tcx.mk_adt(*adt, identity_substs);
|
||||
let base_generic_arg = identity_substs[param_index as usize];
|
||||
let adt_desc = adt.descr();
|
||||
|
||||
|
@ -410,7 +410,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
"returns a closure that contains a reference to a captured variable, which then \
|
||||
escapes the closure body"
|
||||
}
|
||||
ty::Adt(def, _) if self.infcx.tcx.is_diagnostic_item(sym::gen_future, def.did) => {
|
||||
ty::Adt(def, _) if self.infcx.tcx.is_diagnostic_item(sym::gen_future, def.did()) => {
|
||||
"returns an `async` block that contains a reference to a captured variable, which then \
|
||||
escapes the closure body"
|
||||
}
|
||||
|
|
|
@ -736,13 +736,13 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
}
|
||||
ProjectionElem::Downcast(maybe_name, index) => match base_ty.kind() {
|
||||
ty::Adt(adt_def, _substs) if adt_def.is_enum() => {
|
||||
if index.as_usize() >= adt_def.variants.len() {
|
||||
if index.as_usize() >= adt_def.variants().len() {
|
||||
PlaceTy::from_ty(span_mirbug_and_err!(
|
||||
self,
|
||||
place,
|
||||
"cast to variant #{:?} but enum only has {:?}",
|
||||
index,
|
||||
adt_def.variants.len()
|
||||
adt_def.variants().len()
|
||||
))
|
||||
} else {
|
||||
PlaceTy { ty: base_ty, variant_index: Some(index) }
|
||||
|
@ -816,7 +816,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
|
||||
let (variant, substs) = match base_ty {
|
||||
PlaceTy { ty, variant_index: Some(variant_index) } => match *ty.kind() {
|
||||
ty::Adt(adt_def, substs) => (&adt_def.variants[variant_index], substs),
|
||||
ty::Adt(adt_def, substs) => (adt_def.variant(variant_index), substs),
|
||||
ty::Generator(def_id, substs, _) => {
|
||||
let mut variants = substs.as_generator().state_tys(def_id, tcx);
|
||||
let Some(mut variant) = variants.nth(variant_index.into()) else {
|
||||
|
@ -835,7 +835,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
},
|
||||
PlaceTy { ty, variant_index: None } => match *ty.kind() {
|
||||
ty::Adt(adt_def, substs) if !adt_def.is_enum() => {
|
||||
(&adt_def.variants[VariantIdx::new(0)], substs)
|
||||
(adt_def.variant(VariantIdx::new(0)), substs)
|
||||
}
|
||||
ty::Closure(_, substs) => {
|
||||
return match substs
|
||||
|
@ -1449,7 +1449,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
};
|
||||
if variant_index.as_usize() >= adt.variants.len() {
|
||||
if variant_index.as_usize() >= adt.variants().len() {
|
||||
span_bug!(
|
||||
stmt.source_info.span,
|
||||
"bad set discriminant ({:?} = {:?}): value of of range",
|
||||
|
@ -1928,7 +1928,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
match *ak {
|
||||
AggregateKind::Adt(adt_did, variant_index, substs, _, active_field_index) => {
|
||||
let def = tcx.adt_def(adt_did);
|
||||
let variant = &def.variants[variant_index];
|
||||
let variant = &def.variant(variant_index);
|
||||
let adj_field_index = active_field_index.unwrap_or(field_index);
|
||||
if let Some(field) = variant.fields.get(adj_field_index) {
|
||||
Ok(self.normalize(field.ty(tcx, substs), location))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue