Auto merge of #104986 - compiler-errors:opaques, r=oli-obk
Combine `ty::Projection` and `ty::Opaque` into `ty::Alias` Implements https://github.com/rust-lang/types-team/issues/79. This PR consolidates `ty::Projection` and `ty::Opaque` into a single `ty::Alias`, with an `AliasKind` and `AliasTy` type (renamed from `ty::ProjectionTy`, which is the inner data of `ty::Projection`) defined as so: ``` enum AliasKind { Projection, Opaque, } struct AliasTy<'tcx> { def_id: DefId, substs: SubstsRef<'tcx>, } ``` Since we don't have access to `TyCtxt` in type flags computation, and because repeatedly calling `DefKind` on the def-id is expensive, these two types are distinguished with `ty::AliasKind`, conveniently glob-imported into `ty::{Projection, Opaque}`. For example: ```diff match ty.kind() { - ty::Opaque(..) => + ty::Alias(ty::Opaque, ..) => {} _ => {} } ``` This PR also consolidates match arms that treated `ty::Opaque` and `ty::Projection` identically. r? `@ghost`
This commit is contained in:
commit
918d0ac38e
115 changed files with 632 additions and 674 deletions
|
@ -88,10 +88,7 @@ trait DefIdVisitor<'tcx> {
|
|||
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
self.skeleton().visit_trait(trait_ref)
|
||||
}
|
||||
fn visit_projection_ty(
|
||||
&mut self,
|
||||
projection: ty::ProjectionTy<'tcx>,
|
||||
) -> ControlFlow<Self::BreakTy> {
|
||||
fn visit_projection_ty(&mut self, projection: ty::AliasTy<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
self.skeleton().visit_projection_ty(projection)
|
||||
}
|
||||
fn visit_predicates(
|
||||
|
@ -118,18 +115,15 @@ where
|
|||
if self.def_id_visitor.shallow() { ControlFlow::CONTINUE } else { substs.visit_with(self) }
|
||||
}
|
||||
|
||||
fn visit_projection_ty(
|
||||
&mut self,
|
||||
projection: ty::ProjectionTy<'tcx>,
|
||||
) -> ControlFlow<V::BreakTy> {
|
||||
fn visit_projection_ty(&mut self, projection: ty::AliasTy<'tcx>) -> ControlFlow<V::BreakTy> {
|
||||
let tcx = self.def_id_visitor.tcx();
|
||||
let (trait_ref, assoc_substs) = if tcx.def_kind(projection.item_def_id)
|
||||
let (trait_ref, assoc_substs) = if tcx.def_kind(projection.def_id)
|
||||
!= DefKind::ImplTraitPlaceholder
|
||||
{
|
||||
projection.trait_ref_and_own_substs(tcx)
|
||||
} else {
|
||||
// HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys
|
||||
let def_id = tcx.impl_trait_in_trait_parent(projection.item_def_id);
|
||||
let def_id = tcx.impl_trait_in_trait_parent(projection.def_id);
|
||||
let trait_generics = tcx.generics_of(def_id);
|
||||
(
|
||||
ty::TraitRef { def_id, substs: projection.substs.truncate_to(tcx, trait_generics) },
|
||||
|
@ -214,7 +208,7 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
ty::Projection(proj) => {
|
||||
ty::Alias(ty::Projection, proj) => {
|
||||
if self.def_id_visitor.skip_assoc_tys() {
|
||||
// Visitors searching for minimal visibility/reachability want to
|
||||
// conservatively approximate associated types like `<Type as Trait>::Alias`
|
||||
|
@ -241,7 +235,7 @@ where
|
|||
self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)?;
|
||||
}
|
||||
}
|
||||
ty::Opaque(def_id, ..) => {
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => {
|
||||
// Skip repeated `Opaque`s to avoid infinite recursion.
|
||||
if self.visited_opaque_tys.insert(def_id) {
|
||||
// The intent is to treat `impl Trait1 + Trait2` identically to
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue