Replace RPITIT current impl with new strategy that lowers as a GAT
This commit is contained in:
parent
d1389b9b48
commit
20429af7a3
146 changed files with 1106 additions and 586 deletions
|
@ -195,13 +195,7 @@ impl<'hir> Map<'hir> {
|
|||
ItemKind::Fn(..) => DefKind::Fn,
|
||||
ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind),
|
||||
ItemKind::Mod(..) => DefKind::Mod,
|
||||
ItemKind::OpaqueTy(ref opaque) => {
|
||||
if opaque.in_trait && !self.tcx.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||
DefKind::ImplTraitPlaceholder
|
||||
} else {
|
||||
DefKind::OpaqueTy
|
||||
}
|
||||
}
|
||||
ItemKind::OpaqueTy(..) => DefKind::OpaqueTy,
|
||||
ItemKind::TyAlias(..) => DefKind::TyAlias,
|
||||
ItemKind::Enum(..) => DefKind::Enum,
|
||||
ItemKind::Struct(..) => DefKind::Struct,
|
||||
|
|
|
@ -1036,7 +1036,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
scope_def_id: LocalDefId,
|
||||
) -> Vec<&'tcx hir::Ty<'tcx>> {
|
||||
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
|
||||
let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) = self.hir().fn_decl_by_hir_id(hir_id) else {
|
||||
let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) =
|
||||
self.hir().fn_decl_by_hir_id(hir_id)
|
||||
else {
|
||||
return vec![];
|
||||
};
|
||||
|
||||
|
@ -2002,16 +2004,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn lower_impl_trait_in_trait_to_assoc_ty(self) -> bool {
|
||||
self.sess.opts.unstable_opts.lower_impl_trait_in_trait_to_assoc_ty
|
||||
}
|
||||
|
||||
pub fn is_impl_trait_in_trait(self, def_id: DefId) -> bool {
|
||||
if self.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||
self.opt_rpitit_info(def_id).is_some()
|
||||
} else {
|
||||
self.def_kind(def_id) == DefKind::ImplTraitPlaceholder
|
||||
}
|
||||
self.opt_rpitit_info(def_id).is_some()
|
||||
}
|
||||
|
||||
/// Named module children from all kinds of items, including imports.
|
||||
|
|
|
@ -2688,7 +2688,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
| Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) => fn_def_id,
|
||||
None => {
|
||||
while let def_kind = self.def_kind(def_id) && def_kind != DefKind::AssocFn {
|
||||
debug_assert_eq!(def_kind, DefKind::ImplTraitPlaceholder);
|
||||
def_id = self.parent(def_id);
|
||||
}
|
||||
def_id
|
||||
|
@ -2720,26 +2719,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
let Some(trait_item_def_id) = item.trait_item_def_id else { return false; };
|
||||
|
||||
if self.lower_impl_trait_in_trait_to_assoc_ty() {
|
||||
return !self
|
||||
.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)
|
||||
.is_empty();
|
||||
}
|
||||
|
||||
// FIXME(RPITIT): This does a somewhat manual walk through the signature
|
||||
// of the trait fn to look for any RPITITs, but that's kinda doing a lot
|
||||
// of work. We can probably remove this when we refactor RPITITs to be
|
||||
// associated types.
|
||||
self.fn_sig(trait_item_def_id).subst_identity().skip_binder().output().walk().any(|arg| {
|
||||
if let ty::GenericArgKind::Type(ty) = arg.unpack()
|
||||
&& let ty::Alias(ty::Projection, data) = ty.kind()
|
||||
&& self.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder
|
||||
{
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
return !self
|
||||
.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)
|
||||
.is_empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -567,15 +567,9 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
|||
|
||||
// Alias tend to mostly already be handled downstream due to normalization.
|
||||
(&ty::Alias(a_kind, a_data), &ty::Alias(b_kind, b_data)) => {
|
||||
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): This if can be removed
|
||||
// and the assert uncommented once the new desugaring is stable.
|
||||
if a_kind == b_kind {
|
||||
let alias_ty = relation.relate(a_data, b_data)?;
|
||||
// assert_eq!(a_kind, b_kind);
|
||||
Ok(Ty::new_alias(tcx, a_kind, alias_ty))
|
||||
} else {
|
||||
Err(TypeError::Sorts(expected_found(relation, a, b)))
|
||||
}
|
||||
let alias_ty = relation.relate(a_data, b_data)?;
|
||||
assert_eq!(a_kind, b_kind);
|
||||
Ok(Ty::new_alias(tcx, a_kind, alias_ty))
|
||||
}
|
||||
|
||||
_ => Err(TypeError::Sorts(expected_found(relation, a, b))),
|
||||
|
|
|
@ -1237,7 +1237,7 @@ impl<'tcx> AliasTy<'tcx> {
|
|||
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
|
||||
match tcx.def_kind(self.def_id) {
|
||||
DefKind::AssocTy if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(self.def_id)) => ty::Inherent,
|
||||
DefKind::AssocTy | DefKind::ImplTraitPlaceholder => ty::Projection,
|
||||
DefKind::AssocTy => ty::Projection,
|
||||
DefKind::OpaqueTy => ty::Opaque,
|
||||
DefKind::TyAlias => ty::Weak,
|
||||
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
|
||||
|
@ -1265,9 +1265,6 @@ impl<'tcx> AliasTy<'tcx> {
|
|||
pub fn trait_def_id(self, tcx: TyCtxt<'tcx>) -> DefId {
|
||||
match tcx.def_kind(self.def_id) {
|
||||
DefKind::AssocTy | DefKind::AssocConst => tcx.parent(self.def_id),
|
||||
DefKind::ImplTraitPlaceholder => {
|
||||
tcx.parent(tcx.impl_trait_in_trait_parent_fn(self.def_id))
|
||||
}
|
||||
kind => bug!("expected a projection AliasTy; found {kind:?}"),
|
||||
}
|
||||
}
|
||||
|
@ -1970,7 +1967,6 @@ impl<'tcx> Ty<'tcx> {
|
|||
(kind, tcx.def_kind(alias_ty.def_id)),
|
||||
(ty::Opaque, DefKind::OpaqueTy)
|
||||
| (ty::Projection | ty::Inherent, DefKind::AssocTy)
|
||||
| (ty::Opaque | ty::Projection, DefKind::ImplTraitPlaceholder)
|
||||
| (ty::Weak, DefKind::TyAlias)
|
||||
);
|
||||
Ty::new(tcx, Alias(kind, alias_ty))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue