Auto merge of #106910 - aliemjay:alias-ty-in-regionck, r=oli-obk
even more unify Projection/Opaque handling in region outlives code edit: This continues ate the same pace as #106829. New changes are described in https://github.com/rust-lang/rust/pull/106910#issuecomment-1383251254. ~This touches `OutlivesBound`, `Component`, `GenericKind` enums.~ r? `@oli-obk` (because of overlap with #95474)
This commit is contained in:
commit
19423b5944
13 changed files with 108 additions and 151 deletions
|
@ -213,5 +213,5 @@ pub struct NormalizationResult<'tcx> {
|
|||
pub enum OutlivesBound<'tcx> {
|
||||
RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
|
||||
RegionSubParam(ty::Region<'tcx>, ty::ParamTy),
|
||||
RegionSubAlias(ty::Region<'tcx>, ty::AliasKind, ty::AliasTy<'tcx>),
|
||||
RegionSubAlias(ty::Region<'tcx>, ty::AliasTy<'tcx>),
|
||||
}
|
||||
|
|
|
@ -1245,11 +1245,26 @@ pub struct AliasTy<'tcx> {
|
|||
/// aka. `tcx.parent(def_id)`.
|
||||
pub def_id: DefId,
|
||||
|
||||
/// This field exists to prevent the creation of `ProjectionTy` without using
|
||||
/// This field exists to prevent the creation of `AliasTy` without using
|
||||
/// [TyCtxt::mk_alias_ty].
|
||||
pub(super) _use_mk_alias_ty_instead: (),
|
||||
}
|
||||
|
||||
impl<'tcx> AliasTy<'tcx> {
|
||||
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
|
||||
match tcx.def_kind(self.def_id) {
|
||||
DefKind::AssocTy | DefKind::ImplTraitPlaceholder => ty::Projection,
|
||||
DefKind::OpaqueTy => ty::Opaque,
|
||||
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||
tcx.mk_ty(ty::Alias(self.kind(tcx), self))
|
||||
}
|
||||
}
|
||||
|
||||
/// The following methods work only with associated type projections.
|
||||
impl<'tcx> AliasTy<'tcx> {
|
||||
pub fn trait_def_id(self, tcx: TyCtxt<'tcx>) -> DefId {
|
||||
match tcx.def_kind(self.def_id) {
|
||||
|
@ -1257,7 +1272,7 @@ impl<'tcx> AliasTy<'tcx> {
|
|||
DefKind::ImplTraitPlaceholder => {
|
||||
tcx.parent(tcx.impl_trait_in_trait_parent(self.def_id))
|
||||
}
|
||||
kind => bug!("unexpected DefKind in ProjectionTy: {kind:?}"),
|
||||
kind => bug!("expected a projection AliasTy; found {kind:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue