Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU
Switch to `EarlyBinder` for `type_of` query Part of the work to finish #105779 and implement https://github.com/rust-lang/types-team/issues/78. Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `type_of` query and removes `bound_type_of`. r? `@lcnr`
This commit is contained in:
commit
9556b56dbd
164 changed files with 443 additions and 334 deletions
|
@ -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.type_of(def_id).subst_identity()]),
|
||||
}
|
||||
}
|
||||
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),
|
||||
|
|
|
@ -53,7 +53,8 @@ fn inner_resolve_instance<'tcx>(
|
|||
)
|
||||
} 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 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) => {
|
||||
|
|
|
@ -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
|
||||
.type_of(last_field.did)
|
||||
.subst_identity()
|
||||
.is_sized(tcx, param_env),
|
||||
None => false,
|
||||
}
|
||||
},
|
||||
|
|
|
@ -242,7 +242,7 @@ fn drop_tys_helper<'tcx>(
|
|||
Ok(Vec::new())
|
||||
} else {
|
||||
let field_tys = adt_def.all_fields().map(|field| {
|
||||
let r = tcx.bound_type_of(field.did).subst(tcx, substs);
|
||||
let r = tcx.type_of(field.did).subst(tcx, substs);
|
||||
debug!("drop_tys_helper: Subst into {:?} with {:?} gettng {:?}", field, substs, r);
|
||||
r
|
||||
});
|
||||
|
@ -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.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.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,
|
||||
|
|
|
@ -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.type_of(def_id).subst_identity()),
|
||||
def_kind => bug!("unexpected {def_kind:?}"),
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ 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.type_of(field.did).subst_identity(), &mut params_in_repr);
|
||||
}
|
||||
}
|
||||
params_in_repr
|
||||
|
|
|
@ -105,7 +105,7 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
|
|||
def.variants()
|
||||
.iter()
|
||||
.flat_map(|v| v.fields.last())
|
||||
.flat_map(|f| sized_constraint_for_ty(tcx, def, tcx.type_of(f.did))),
|
||||
.flat_map(|f| sized_constraint_for_ty(tcx, def, tcx.type_of(f.did).subst_identity())),
|
||||
);
|
||||
|
||||
debug!("adt_sized_constraint: {:?} => {:?}", def, result);
|
||||
|
@ -301,7 +301,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.type_of(def_id).subst_identity();
|
||||
inputs.extend(self_ty.walk());
|
||||
}
|
||||
|
||||
|
@ -436,7 +436,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32
|
|||
};
|
||||
|
||||
let mut unsizing_params = BitSet::new_empty(num_params);
|
||||
for arg in tcx.bound_type_of(tail_field.did).subst_identity().walk() {
|
||||
for arg in tcx.type_of(tail_field.did).subst_identity().walk() {
|
||||
if let Some(i) = maybe_unsizing_param_idx(arg) {
|
||||
unsizing_params.insert(i);
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32
|
|||
// Ensure none of the other fields mention the parameters used
|
||||
// in unsizing.
|
||||
for field in prefix_fields {
|
||||
for arg in tcx.bound_type_of(field.did).subst_identity().walk() {
|
||||
for arg in tcx.type_of(field.did).subst_identity().walk() {
|
||||
if let Some(i) = maybe_unsizing_param_idx(arg) {
|
||||
unsizing_params.remove(i);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue