IdentitySubsts::identity_for_item takes Into<DefId>
This commit is contained in:
parent
979ef5981f
commit
7e6506764b
14 changed files with 27 additions and 28 deletions
|
@ -284,7 +284,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
||||||
// hidden type is well formed even without those bounds.
|
// hidden type is well formed even without those bounds.
|
||||||
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()));
|
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
|
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
|
||||||
// the bounds that the function supplies.
|
// the bounds that the function supplies.
|
||||||
|
|
|
@ -211,7 +211,7 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
||||||
return;
|
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);
|
let span = tcx.def_span(item.owner_id.def_id);
|
||||||
|
|
||||||
if !tcx.features().impl_trait_projections {
|
if !tcx.features().impl_trait_projections {
|
||||||
|
@ -304,7 +304,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
|
||||||
..
|
..
|
||||||
}) = item.kind
|
}) = 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 {
|
let opaque_identity_ty = if in_trait {
|
||||||
tcx.mk_projection(def_id.to_def_id(), substs)
|
tcx.mk_projection(def_id.to_def_id(), substs)
|
||||||
} else {
|
} else {
|
||||||
|
@ -535,7 +535,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
||||||
}
|
}
|
||||||
ty::AssocKind::Type if assoc_item.defaultness(tcx).has_value() => {
|
ty::AssocKind::Type if assoc_item.defaultness(tcx).has_value() => {
|
||||||
let trait_substs =
|
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(
|
let _: Result<_, rustc_errors::ErrorGuaranteed> = check_type_bounds(
|
||||||
tcx,
|
tcx,
|
||||||
assoc_item,
|
assoc_item,
|
||||||
|
|
|
@ -22,7 +22,7 @@ fn associated_type_bounds<'tcx>(
|
||||||
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
|
||||||
let item_ty = tcx.mk_projection(
|
let item_ty = tcx.mk_projection(
|
||||||
assoc_item_def_id.to_def_id(),
|
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);
|
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
|
||||||
|
@ -92,7 +92,7 @@ pub(super) fn explicit_item_bounds(
|
||||||
opaque_ty.bounds,
|
opaque_ty.bounds,
|
||||||
tcx.mk_projection(
|
tcx.mk_projection(
|
||||||
def_id.to_def_id(),
|
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,
|
item.span,
|
||||||
);
|
);
|
||||||
|
@ -114,7 +114,7 @@ pub(super) fn explicit_item_bounds(
|
||||||
span,
|
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() {
|
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||||
tcx.mk_projection(def_id.to_def_id(), substs)
|
tcx.mk_projection(def_id.to_def_id(), substs)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -405,7 +405,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
|
||||||
// Remove bounds on associated types from the predicates, they will be
|
// Remove bounds on associated types from the predicates, they will be
|
||||||
// returned by `explicit_item_bounds`.
|
// returned by `explicit_item_bounds`.
|
||||||
let predicates_and_bounds = tcx.trait_explicit_predicates_and_bounds(def_id);
|
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>| {
|
let is_assoc_item_ty = |ty: Ty<'tcx>| {
|
||||||
// For a predicate from a where clause to become a bound on an
|
// For a predicate from a where clause to become a bound on an
|
||||||
|
|
|
@ -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) {
|
let output = match tcx.hir().get(hir_id) {
|
||||||
Node::TraitItem(item) => match item.kind {
|
Node::TraitItem(item) => match item.kind {
|
||||||
TraitItemKind::Fn(..) => {
|
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)
|
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||||
}
|
}
|
||||||
TraitItemKind::Const(ty, body_id) => body_id
|
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 {
|
Node::ImplItem(item) => match item.kind {
|
||||||
ImplItemKind::Fn(..) => {
|
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)
|
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||||
}
|
}
|
||||||
ImplItemKind::Const(ty, body_id) => {
|
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),
|
_ => icx.to_ty(*self_ty),
|
||||||
},
|
},
|
||||||
ItemKind::Fn(..) => {
|
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)
|
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||||
}
|
}
|
||||||
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
|
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
|
||||||
let def = tcx.adt_def(def_id);
|
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)
|
tcx.mk_adt(def, substs)
|
||||||
}
|
}
|
||||||
ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => {
|
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 {
|
Node::ForeignItem(foreign_item) => match foreign_item.kind {
|
||||||
ForeignItemKind::Fn(..) => {
|
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)
|
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||||
}
|
}
|
||||||
ForeignItemKind::Static(t, _) => icx.to_ty(t),
|
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()
|
tcx.type_of(tcx.hir().get_parent_item(hir_id)).subst_identity()
|
||||||
}
|
}
|
||||||
VariantData::Tuple(..) => {
|
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)
|
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), .. })
|
Node::Expr(Expr { kind: ExprKind::ConstBlock(anon_const), .. })
|
||||||
if anon_const.hir_id == hir_id =>
|
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()
|
substs.as_inline_const().ty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ fn get_impl_substs(
|
||||||
let assumed_wf_types =
|
let assumed_wf_types =
|
||||||
ocx.assumed_wf_types(param_env, tcx.def_span(impl1_def_id), impl1_def_id);
|
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 =
|
let impl2_substs =
|
||||||
translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node);
|
translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node);
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
||||||
|
|
||||||
let mut collector =
|
let mut collector =
|
||||||
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
|
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() {
|
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);
|
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
|
||||||
debug!(?pred);
|
debug!(?pred);
|
||||||
|
|
|
@ -306,8 +306,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
// Replace the explicit self type with `Self` for better suggestion rendering
|
// Replace the explicit self type with `Self` for better suggestion rendering
|
||||||
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper))
|
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper))
|
||||||
.substs;
|
.substs;
|
||||||
let trait_item_substs =
|
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
|
||||||
ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id.to_def_id())
|
|
||||||
.rebase_onto(self.tcx, impl_def_id, trait_substs);
|
.rebase_onto(self.tcx, impl_def_id, trait_substs);
|
||||||
|
|
||||||
let Ok(trait_predicates) = self
|
let Ok(trait_predicates) = self
|
||||||
|
|
|
@ -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 parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id)
|
||||||
&& let Some(parent_did) = parent_hir_id.as_owner()
|
&& 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 {
|
} else {
|
||||||
List::empty()
|
List::empty()
|
||||||
};
|
};
|
||||||
|
@ -2554,7 +2554,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
||||||
Self::Unevaluated(
|
Self::Unevaluated(
|
||||||
UnevaluatedConst {
|
UnevaluatedConst {
|
||||||
def: def.to_global(),
|
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,
|
promoted: None,
|
||||||
},
|
},
|
||||||
ty,
|
ty,
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl<'tcx> Const<'tcx> {
|
||||||
None => tcx.mk_const(
|
None => tcx.mk_const(
|
||||||
ty::UnevaluatedConst {
|
ty::UnevaluatedConst {
|
||||||
def: def.to_global(),
|
def: def.to_global(),
|
||||||
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
|
substs: InternalSubsts::identity_for_item(tcx, def.did),
|
||||||
},
|
},
|
||||||
ty,
|
ty,
|
||||||
),
|
),
|
||||||
|
|
|
@ -1385,7 +1385,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
|
||||||
// lifetimes with 'static and remapping only those used in the
|
// lifetimes with 'static and remapping only those used in the
|
||||||
// `impl Trait` return type, resulting in the parameters
|
// `impl Trait` return type, resulting in the parameters
|
||||||
// shifting.
|
// 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);
|
debug!(?id_substs);
|
||||||
|
|
||||||
// This zip may have several times the same lifetime in `substs` paired with a different
|
// This zip may have several times the same lifetime in `substs` paired with a different
|
||||||
|
|
|
@ -302,8 +302,8 @@ impl<'tcx> InternalSubsts<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an `InternalSubsts` that maps each generic parameter to itself.
|
/// Creates an `InternalSubsts` that maps each generic parameter to itself.
|
||||||
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
|
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: impl Into<DefId>) -> SubstsRef<'tcx> {
|
||||||
Self::for_item(tcx, def_id, |param, _| tcx.mk_param_from_def(param))
|
Self::for_item(tcx, def_id.into(), |param, _| tcx.mk_param_from_def(param))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an `InternalSubsts` for generic parameter definitions,
|
/// Creates an `InternalSubsts` for generic parameter definitions,
|
||||||
|
|
|
@ -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()) {
|
let trait_substs = match tcx.trait_of_item(def_id.to_def_id()) {
|
||||||
Some(trait_def_id) => {
|
Some(trait_def_id) => {
|
||||||
let trait_substs_count = tcx.generics_of(trait_def_id).count();
|
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]
|
||||||
}
|
}
|
||||||
_ => &[],
|
_ => &[],
|
||||||
};
|
};
|
||||||
|
|
|
@ -296,7 +296,7 @@ fn associated_type_for_impl_trait_in_trait(
|
||||||
// Copy type_of of the opaque.
|
// Copy type_of of the opaque.
|
||||||
trait_assoc_ty.type_of(ty::EarlyBinder(tcx.mk_opaque(
|
trait_assoc_ty.type_of(ty::EarlyBinder(tcx.mk_opaque(
|
||||||
opaque_ty_def_id.to_def_id(),
|
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);
|
trait_assoc_ty.is_type_alias_impl_trait(false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue