IdentitySubsts::identity_for_item takes Into<DefId>

This commit is contained in:
Michael Goulet 2023-03-13 19:35:29 +00:00
parent 979ef5981f
commit 7e6506764b
14 changed files with 27 additions and 28 deletions

View File

@ -284,7 +284,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
// hidden type is well formed even without those bounds.
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()));
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id);
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
// the bounds that the function supplies.

View File

@ -211,7 +211,7 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
return;
}
let substs = InternalSubsts::identity_for_item(tcx, item.owner_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, item.owner_id);
let span = tcx.def_span(item.owner_id.def_id);
if !tcx.features().impl_trait_projections {
@ -304,7 +304,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
..
}) = item.kind
{
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
let opaque_identity_ty = if in_trait {
tcx.mk_projection(def_id.to_def_id(), substs)
} else {
@ -535,7 +535,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
}
ty::AssocKind::Type if assoc_item.defaultness(tcx).has_value() => {
let trait_substs =
InternalSubsts::identity_for_item(tcx, id.owner_id.to_def_id());
InternalSubsts::identity_for_item(tcx, id.owner_id);
let _: Result<_, rustc_errors::ErrorGuaranteed> = check_type_bounds(
tcx,
assoc_item,

View File

@ -22,7 +22,7 @@ fn associated_type_bounds<'tcx>(
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
let item_ty = tcx.mk_projection(
assoc_item_def_id.to_def_id(),
InternalSubsts::identity_for_item(tcx, assoc_item_def_id.to_def_id()),
InternalSubsts::identity_for_item(tcx, assoc_item_def_id),
);
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
@ -92,7 +92,7 @@ pub(super) fn explicit_item_bounds(
opaque_ty.bounds,
tcx.mk_projection(
def_id.to_def_id(),
ty::InternalSubsts::identity_for_item(tcx, def_id.to_def_id()),
ty::InternalSubsts::identity_for_item(tcx, def_id),
),
item.span,
);
@ -114,7 +114,7 @@ pub(super) fn explicit_item_bounds(
span,
..
}) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
tcx.mk_projection(def_id.to_def_id(), substs)
} else {

View File

@ -405,7 +405,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
// Remove bounds on associated types from the predicates, they will be
// returned by `explicit_item_bounds`.
let predicates_and_bounds = tcx.trait_explicit_predicates_and_bounds(def_id);
let trait_identity_substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let trait_identity_substs = InternalSubsts::identity_for_item(tcx, def_id);
let is_assoc_item_ty = |ty: Ty<'tcx>| {
// For a predicate from a where clause to become a bound on an

View File

@ -274,7 +274,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
let output = match tcx.hir().get(hir_id) {
Node::TraitItem(item) => match item.kind {
TraitItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs)
}
TraitItemKind::Const(ty, body_id) => body_id
@ -294,7 +294,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
Node::ImplItem(item) => match item.kind {
ImplItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs)
}
ImplItemKind::Const(ty, body_id) => {
@ -350,12 +350,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
_ => icx.to_ty(*self_ty),
},
ItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs)
}
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
let def = tcx.adt_def(def_id);
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_adt(def, substs)
}
ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => {
@ -395,7 +395,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
Node::ForeignItem(foreign_item) => match foreign_item.kind {
ForeignItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs)
}
ForeignItemKind::Static(t, _) => icx.to_ty(t),
@ -407,7 +407,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
tcx.type_of(tcx.hir().get_parent_item(hir_id)).subst_identity()
}
VariantData::Tuple(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_fn_def(def_id.to_def_id(), substs)
}
},
@ -440,7 +440,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
Node::Expr(Expr { kind: ExprKind::ConstBlock(anon_const), .. })
if anon_const.hir_id == hir_id =>
{
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let substs = InternalSubsts::identity_for_item(tcx, def_id);
substs.as_inline_const().ty()
}

View File

@ -168,7 +168,7 @@ fn get_impl_substs(
let assumed_wf_types =
ocx.assumed_wf_types(param_env, tcx.def_span(impl1_def_id), impl1_def_id);
let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id.to_def_id());
let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id);
let impl2_substs =
translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node);

View File

@ -152,7 +152,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
let mut collector =
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id.to_def_id());
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id);
for pred in tcx.bound_explicit_item_bounds(item_def_id.to_def_id()).transpose_iter() {
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
debug!(?pred);

View File

@ -306,9 +306,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// Replace the explicit self type with `Self` for better suggestion rendering
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper))
.substs;
let trait_item_substs =
ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id.to_def_id())
.rebase_onto(self.tcx, impl_def_id, trait_substs);
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
.rebase_onto(self.tcx, impl_def_id, trait_substs);
let Ok(trait_predicates) = self
.tcx

View File

@ -2525,7 +2525,7 @@ impl<'tcx> ConstantKind<'tcx> {
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id)
&& let Some(parent_did) = parent_hir_id.as_owner()
{
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
InternalSubsts::identity_for_item(tcx, parent_did)
} else {
List::empty()
};
@ -2554,7 +2554,7 @@ impl<'tcx> ConstantKind<'tcx> {
Self::Unevaluated(
UnevaluatedConst {
def: def.to_global(),
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
substs: InternalSubsts::identity_for_item(tcx, def.did),
promoted: None,
},
ty,

View File

@ -83,7 +83,7 @@ impl<'tcx> Const<'tcx> {
None => tcx.mk_const(
ty::UnevaluatedConst {
def: def.to_global(),
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
substs: InternalSubsts::identity_for_item(tcx, def.did),
},
ty,
),

View File

@ -1385,7 +1385,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
// lifetimes with 'static and remapping only those used in the
// `impl Trait` return type, resulting in the parameters
// shifting.
let id_substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
let id_substs = InternalSubsts::identity_for_item(tcx, def_id);
debug!(?id_substs);
// This zip may have several times the same lifetime in `substs` paired with a different

View File

@ -302,8 +302,8 @@ impl<'tcx> InternalSubsts<'tcx> {
}
/// Creates an `InternalSubsts` that maps each generic parameter to itself.
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
Self::for_item(tcx, def_id, |param, _| tcx.mk_param_from_def(param))
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: impl Into<DefId>) -> SubstsRef<'tcx> {
Self::for_item(tcx, def_id.into(), |param, _| tcx.mk_param_from_def(param))
}
/// Creates an `InternalSubsts` for generic parameter definitions,

View File

@ -18,7 +18,7 @@ pub(crate) fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
let trait_substs = match tcx.trait_of_item(def_id.to_def_id()) {
Some(trait_def_id) => {
let trait_substs_count = tcx.generics_of(trait_def_id).count();
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
&InternalSubsts::identity_for_item(tcx, def_id)[..trait_substs_count]
}
_ => &[],
};

View File

@ -296,7 +296,7 @@ fn associated_type_for_impl_trait_in_trait(
// Copy type_of of the opaque.
trait_assoc_ty.type_of(ty::EarlyBinder(tcx.mk_opaque(
opaque_ty_def_id.to_def_id(),
InternalSubsts::identity_for_item(tcx, opaque_ty_def_id.to_def_id()),
InternalSubsts::identity_for_item(tcx, opaque_ty_def_id),
)));
trait_assoc_ty.is_type_alias_impl_trait(false);