RPITITs are DefKind::Opaque with new lowering strategy
This commit is contained in:
parent
c1f3529c91
commit
c3e6f68931
4 changed files with 36 additions and 15 deletions
|
@ -305,7 +305,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
|
||||||
}) = item.kind
|
}) = item.kind
|
||||||
{
|
{
|
||||||
let substs = InternalSubsts::identity_for_item(tcx, 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.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 {
|
||||||
tcx.mk_opaque(def_id.to_def_id(), substs)
|
tcx.mk_opaque(def_id.to_def_id(), substs)
|
||||||
|
@ -554,8 +554,16 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
||||||
check_union(tcx, id.owner_id.def_id);
|
check_union(tcx, id.owner_id.def_id);
|
||||||
}
|
}
|
||||||
DefKind::OpaqueTy => {
|
DefKind::OpaqueTy => {
|
||||||
|
let opaque = tcx.hir().expect_item(id.owner_id.def_id).expect_opaque_ty();
|
||||||
|
if let hir::OpaqueTyOrigin::FnReturn(fn_def_id) | hir::OpaqueTyOrigin::AsyncFn(fn_def_id) = opaque.origin
|
||||||
|
&& let hir::Node::TraitItem(trait_item) = tcx.hir().get_by_def_id(fn_def_id)
|
||||||
|
&& let (_, hir::TraitFn::Required(..)) = trait_item.expect_fn()
|
||||||
|
{
|
||||||
|
// Skip opaques from RPIT in traits with no default body.
|
||||||
|
} else {
|
||||||
check_opaque(tcx, id);
|
check_opaque(tcx, id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
DefKind::ImplTraitPlaceholder => {
|
DefKind::ImplTraitPlaceholder => {
|
||||||
let parent = tcx.impl_trait_in_trait_parent_fn(id.owner_id.to_def_id());
|
let parent = tcx.impl_trait_in_trait_parent_fn(id.owner_id.to_def_id());
|
||||||
// Only check the validity of this opaque type if the function has a default body
|
// Only check the validity of this opaque type if the function has a default body
|
||||||
|
|
|
@ -1016,7 +1016,6 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
|
||||||
| DefKind::Const
|
| DefKind::Const
|
||||||
| DefKind::Static(..)
|
| DefKind::Static(..)
|
||||||
| DefKind::TyAlias
|
| DefKind::TyAlias
|
||||||
| DefKind::OpaqueTy
|
|
||||||
| DefKind::ForeignTy
|
| DefKind::ForeignTy
|
||||||
| DefKind::Impl { .. }
|
| DefKind::Impl { .. }
|
||||||
| DefKind::AssocFn
|
| DefKind::AssocFn
|
||||||
|
@ -1027,6 +1026,18 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
|
||||||
| DefKind::AnonConst
|
| DefKind::AnonConst
|
||||||
| DefKind::InlineConst => true,
|
| DefKind::InlineConst => true,
|
||||||
|
|
||||||
|
DefKind::OpaqueTy => {
|
||||||
|
let opaque = tcx.hir().expect_item(def_id).expect_opaque_ty();
|
||||||
|
if let hir::OpaqueTyOrigin::FnReturn(fn_def_id) | hir::OpaqueTyOrigin::AsyncFn(fn_def_id) = opaque.origin
|
||||||
|
&& let hir::Node::TraitItem(trait_item) = tcx.hir().get_by_def_id(fn_def_id)
|
||||||
|
&& let (_, hir::TraitFn::Required(..)) = trait_item.expect_fn()
|
||||||
|
{
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DefKind::ImplTraitPlaceholder => {
|
DefKind::ImplTraitPlaceholder => {
|
||||||
let parent_def_id = tcx.impl_trait_in_trait_parent_fn(def_id.to_def_id());
|
let parent_def_id = tcx.impl_trait_in_trait_parent_fn(def_id.to_def_id());
|
||||||
let assoc_item = tcx.associated_item(parent_def_id);
|
let assoc_item = tcx.associated_item(parent_def_id);
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl<'hir> Map<'hir> {
|
||||||
ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind),
|
ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind),
|
||||||
ItemKind::Mod(..) => DefKind::Mod,
|
ItemKind::Mod(..) => DefKind::Mod,
|
||||||
ItemKind::OpaqueTy(ref opaque) => {
|
ItemKind::OpaqueTy(ref opaque) => {
|
||||||
if opaque.in_trait {
|
if opaque.in_trait && !self.tcx.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||||
DefKind::ImplTraitPlaceholder
|
DefKind::ImplTraitPlaceholder
|
||||||
} else {
|
} else {
|
||||||
DefKind::OpaqueTy
|
DefKind::OpaqueTy
|
||||||
|
|
|
@ -254,13 +254,16 @@ fn associated_type_for_impl_trait_in_trait(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
opaque_ty_def_id: LocalDefId,
|
opaque_ty_def_id: LocalDefId,
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
let fn_def_id = tcx.impl_trait_in_trait_parent_fn(opaque_ty_def_id.to_def_id());
|
let (hir::OpaqueTyOrigin::FnReturn(fn_def_id) | hir::OpaqueTyOrigin::AsyncFn(fn_def_id)) =
|
||||||
let trait_def_id = tcx.parent(fn_def_id);
|
tcx.hir().expect_item(opaque_ty_def_id).expect_opaque_ty().origin
|
||||||
|
else {
|
||||||
|
bug!("expected opaque for {opaque_ty_def_id:?}");
|
||||||
|
};
|
||||||
|
let trait_def_id = tcx.local_parent(fn_def_id);
|
||||||
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
|
assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait);
|
||||||
|
|
||||||
let span = tcx.def_span(opaque_ty_def_id);
|
let span = tcx.def_span(opaque_ty_def_id);
|
||||||
let trait_assoc_ty =
|
let trait_assoc_ty = tcx.at(span).create_def(trait_def_id, DefPathData::ImplTraitAssocTy);
|
||||||
tcx.at(span).create_def(trait_def_id.expect_local(), DefPathData::ImplTraitAssocTy);
|
|
||||||
|
|
||||||
let local_def_id = trait_assoc_ty.def_id();
|
let local_def_id = trait_assoc_ty.def_id();
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
|
@ -282,7 +285,7 @@ fn associated_type_for_impl_trait_in_trait(
|
||||||
container: ty::TraitContainer,
|
container: ty::TraitContainer,
|
||||||
fn_has_self_parameter: false,
|
fn_has_self_parameter: false,
|
||||||
opt_rpitit_info: Some(ImplTraitInTraitData::Trait {
|
opt_rpitit_info: Some(ImplTraitInTraitData::Trait {
|
||||||
fn_def_id,
|
fn_def_id: fn_def_id.to_def_id(),
|
||||||
opaque_def_id: opaque_ty_def_id.to_def_id(),
|
opaque_def_id: opaque_ty_def_id.to_def_id(),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
@ -324,7 +327,7 @@ fn associated_type_for_impl_trait_in_trait(
|
||||||
params.iter().map(|param| (param.def_id, param.index)).collect();
|
params.iter().map(|param| (param.def_id, param.index)).collect();
|
||||||
|
|
||||||
ty::Generics {
|
ty::Generics {
|
||||||
parent: Some(trait_def_id),
|
parent: Some(trait_def_id.to_def_id()),
|
||||||
parent_count,
|
parent_count,
|
||||||
params,
|
params,
|
||||||
param_def_id_to_index,
|
param_def_id_to_index,
|
||||||
|
@ -335,7 +338,7 @@ fn associated_type_for_impl_trait_in_trait(
|
||||||
|
|
||||||
// There are no predicates for the synthesized associated type.
|
// There are no predicates for the synthesized associated type.
|
||||||
trait_assoc_ty.explicit_predicates_of(ty::GenericPredicates {
|
trait_assoc_ty.explicit_predicates_of(ty::GenericPredicates {
|
||||||
parent: Some(trait_def_id),
|
parent: Some(trait_def_id.to_def_id()),
|
||||||
predicates: &[],
|
predicates: &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -356,7 +359,6 @@ fn associated_type_for_impl_trait_in_impl(
|
||||||
impl_fn_def_id: LocalDefId,
|
impl_fn_def_id: LocalDefId,
|
||||||
) -> LocalDefId {
|
) -> LocalDefId {
|
||||||
let impl_local_def_id = tcx.local_parent(impl_fn_def_id);
|
let impl_local_def_id = tcx.local_parent(impl_fn_def_id);
|
||||||
let impl_def_id = impl_local_def_id.to_def_id();
|
|
||||||
|
|
||||||
// FIXME fix the span, we probably want the def_id of the return type of the function
|
// FIXME fix the span, we probably want the def_id of the return type of the function
|
||||||
let span = tcx.def_span(impl_fn_def_id);
|
let span = tcx.def_span(impl_fn_def_id);
|
||||||
|
@ -402,7 +404,7 @@ fn associated_type_for_impl_trait_in_impl(
|
||||||
let trait_assoc_parent_count = trait_assoc_generics.parent_count;
|
let trait_assoc_parent_count = trait_assoc_generics.parent_count;
|
||||||
let mut params = trait_assoc_generics.params.clone();
|
let mut params = trait_assoc_generics.params.clone();
|
||||||
|
|
||||||
let parent_generics = tcx.generics_of(impl_def_id);
|
let parent_generics = tcx.generics_of(impl_local_def_id.to_def_id());
|
||||||
let parent_count = parent_generics.parent_count + parent_generics.params.len();
|
let parent_count = parent_generics.parent_count + parent_generics.params.len();
|
||||||
|
|
||||||
for param in &mut params {
|
for param in &mut params {
|
||||||
|
@ -413,7 +415,7 @@ fn associated_type_for_impl_trait_in_impl(
|
||||||
params.iter().map(|param| (param.def_id, param.index)).collect();
|
params.iter().map(|param| (param.def_id, param.index)).collect();
|
||||||
|
|
||||||
ty::Generics {
|
ty::Generics {
|
||||||
parent: Some(impl_def_id),
|
parent: Some(impl_local_def_id.to_def_id()),
|
||||||
parent_count,
|
parent_count,
|
||||||
params,
|
params,
|
||||||
param_def_id_to_index,
|
param_def_id_to_index,
|
||||||
|
@ -424,7 +426,7 @@ fn associated_type_for_impl_trait_in_impl(
|
||||||
|
|
||||||
// There are no predicates for the synthesized associated type.
|
// There are no predicates for the synthesized associated type.
|
||||||
impl_assoc_ty.explicit_predicates_of(ty::GenericPredicates {
|
impl_assoc_ty.explicit_predicates_of(ty::GenericPredicates {
|
||||||
parent: Some(impl_def_id),
|
parent: Some(impl_local_def_id.to_def_id()),
|
||||||
predicates: &[],
|
predicates: &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue