change usages of type_of to bound_type_of

This commit is contained in:
Kyle Matsuda 2023-02-06 17:48:12 -07:00
parent 9a7cc6c32f
commit d822b97a27
136 changed files with 385 additions and 262 deletions

View file

@ -28,7 +28,7 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
tcx.intern_type_list(&types)
}
// Only the impl self type
None => tcx.intern_type_list(&[tcx.type_of(def_id)]),
None => tcx.intern_type_list(&[tcx.bound_type_of(def_id).subst_identity()]),
}
}
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),

View file

@ -52,8 +52,9 @@ fn inner_resolve_instance<'tcx>(
tcx.normalize_erasing_regions(param_env, substs),
)
} else {
let ty = tcx.type_of(def.def_id_for_type_of());
let item_type = tcx.subst_and_normalize_erasing_regions(substs, param_env, ty);
let ty = tcx.bound_type_of(def.def_id_for_type_of());
let item_type =
tcx.subst_and_normalize_erasing_regions(substs, param_env, ty.skip_binder());
let def = match *item_type.kind() {
ty::FnDef(def_id, ..) if tcx.is_intrinsic(def_id) => {

View file

@ -453,9 +453,10 @@ fn layout_of_uncached<'tcx>(
let param_env = tcx.param_env(def.did());
def.is_struct()
&& match def.variants().iter().next().and_then(|x| x.fields.last()) {
Some(last_field) => {
tcx.type_of(last_field.did).is_sized(tcx, param_env)
}
Some(last_field) => tcx
.bound_type_of(last_field.did)
.subst_identity()
.is_sized(tcx, param_env),
None => false,
}
},

View file

@ -295,9 +295,15 @@ fn adt_drop_tys<'tcx>(
let adt_has_dtor =
|adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant);
// `tcx.type_of(def_id)` identical to `tcx.make_adt(def, identity_substs)`
drop_tys_helper(tcx, tcx.type_of(def_id), tcx.param_env(def_id), adt_has_dtor, false)
.collect::<Result<Vec<_>, _>>()
.map(|components| tcx.intern_type_list(&components))
drop_tys_helper(
tcx,
tcx.bound_type_of(def_id).subst_identity(),
tcx.param_env(def_id),
adt_has_dtor,
false,
)
.collect::<Result<Vec<_>, _>>()
.map(|components| tcx.intern_type_list(&components))
}
// If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed
// a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitute the generic parameters
@ -308,7 +314,7 @@ fn adt_significant_drop_tys(
) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> {
drop_tys_helper(
tcx,
tcx.type_of(def_id), // identical to `tcx.make_adt(def, identity_substs)`
tcx.bound_type_of(def_id).subst_identity(), // identical to `tcx.make_adt(def, identity_substs)`
tcx.param_env(def_id),
adt_consider_insignificant_dtor(tcx),
true,

View file

@ -31,7 +31,7 @@ fn representability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Representability {
}
Representability::Representable
}
DefKind::Field => representability_ty(tcx, tcx.type_of(def_id)),
DefKind::Field => representability_ty(tcx, tcx.bound_type_of(def_id).subst_identity()),
def_kind => bug!("unexpected {def_kind:?}"),
}
}
@ -91,7 +91,11 @@ fn params_in_repr(tcx: TyCtxt<'_>, def_id: DefId) -> BitSet<u32> {
let mut params_in_repr = BitSet::new_empty(generics.params.len());
for variant in adt_def.variants() {
for field in variant.fields.iter() {
params_in_repr_ty(tcx, tcx.type_of(field.did), &mut params_in_repr);
params_in_repr_ty(
tcx,
tcx.bound_type_of(field.did).subst_identity(),
&mut params_in_repr,
);
}
}
params_in_repr

View file

@ -99,12 +99,10 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
}
let def = tcx.adt_def(def_id);
let result = tcx.mk_type_list(
def.variants()
.iter()
.flat_map(|v| v.fields.last())
.flat_map(|f| sized_constraint_for_ty(tcx, def, tcx.type_of(f.did))),
);
let result =
tcx.mk_type_list(def.variants().iter().flat_map(|v| v.fields.last()).flat_map(|f| {
sized_constraint_for_ty(tcx, def, tcx.bound_type_of(f.did).subst_identity())
}));
debug!("adt_sized_constraint: {:?} => {:?}", def, result);
@ -299,7 +297,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Predica
// In an inherent impl, we assume that the receiver type and all its
// constituents are well-formed.
NodeKind::InherentImpl => {
let self_ty = tcx.type_of(def_id);
let self_ty = tcx.bound_type_of(def_id).subst_identity();
inputs.extend(self_ty.walk());
}