diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs b/compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs index 5b4a5ac357722..8fa399580f57d 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs @@ -74,7 +74,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { fn print_dyn_existential( mut self, - predicates: &'tcx ty::List>>, + predicates: &'tcx ty::List>, ) -> Result { let mut first = true; for p in predicates { diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 2854e6fd396c2..0f0e08be18783 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -376,11 +376,10 @@ impl Checker<'mir, 'tcx> { ty::Dynamic(preds, _) => { for pred in preds.iter() { match pred.skip_binder() { - ty::ExistentialPredicate::AutoTrait(_) - | ty::ExistentialPredicate::Projection(_) => { + ty::WhereClause::AutoTrait(_) | ty::WhereClause::Projection(_) => { self.check_op(ops::ty::DynTrait(kind)) } - ty::ExistentialPredicate::Trait(trait_ref) => { + ty::WhereClause::Trait(trait_ref) => { if Some(trait_ref.def_id) != self.tcx.lang_items().sized_trait() { self.check_op(ops::ty::DynTrait(kind)) } diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 298346c373e54..f259c655ae7ab 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -482,7 +482,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { fn print_dyn_existential( self, - _predicates: &'tcx ty::List>>, + _predicates: &'tcx ty::List>, ) -> Result { Err(NonTrivialPath) } diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 4c936dec6f2cd..852b2f7676ada 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -994,7 +994,7 @@ impl<'tcx> LateContext<'tcx> { fn print_dyn_existential( self, - _predicates: &'tcx ty::List>>, + _predicates: &'tcx ty::List>, ) -> Result { Ok(()) } diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index da1edcf6fe3b4..5dec1550cf66c 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -222,9 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { ty::Dynamic(binder, _) => { let mut has_emitted = false; for predicate in binder.iter() { - if let ty::ExistentialPredicate::Trait(ref trait_ref) = - predicate.skip_binder() - { + if let ty::WhereClause::Trait(ref trait_ref) = predicate.skip_binder() { let def_id = trait_ref.def_id; let descr_post = &format!(" trait object{}{}", plural_suffix, descr_post,); diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 434008ecb1f4f..6c1b04ef49868 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -322,9 +322,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List> { } } -impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> - for ty::List>> -{ +impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List> { fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> { let len = decoder.read_usize()?; decoder.tcx().mk_poly_existential_predicates((0..len).map(|_| Decodable::decode(decoder))) @@ -393,7 +391,7 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List, &'tcx ty::List>, - &'tcx ty::List>>, + &'tcx ty::List>, &'tcx Allocation, &'tcx mir::Body<'tcx>, &'tcx mir::UnsafetyCheckResult, @@ -519,7 +517,7 @@ macro_rules! impl_binder_encode_decode { impl_binder_encode_decode! { &'tcx ty::List>, ty::FnSig<'tcx>, - ty::ExistentialPredicate<'tcx>, + ty::WhereClause<'tcx>, ty::TraitRef<'tcx>, Vec>, } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 8240273acad4c..182191c0d78ec 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -103,8 +103,7 @@ pub struct CtxtInterners<'tcx> { substs: InternedSet<'tcx, InternalSubsts<'tcx>>, canonical_var_infos: InternedSet<'tcx, List>>, region: InternedSet<'tcx, RegionKind>, - poly_existential_predicates: - InternedSet<'tcx, List>>>, + poly_existential_predicates: InternedSet<'tcx, List>>, predicate: InternedSet<'tcx, PredicateInner<'tcx>>, predicates: InternedSet<'tcx, List>>, projs: InternedSet<'tcx, List>, @@ -1672,7 +1671,7 @@ nop_lift! {const_allocation; &'a Allocation => &'tcx Allocation} nop_lift! {predicate; &'a PredicateInner<'a> => &'tcx PredicateInner<'tcx>} nop_list_lift! {type_list; Ty<'a> => Ty<'tcx>} -nop_list_lift! {poly_existential_predicates; ty::Binder<'a, ExistentialPredicate<'a>> => ty::Binder<'tcx, ExistentialPredicate<'tcx>>} +nop_list_lift! {poly_existential_predicates; ExistentialPredicate<'a> => ExistentialPredicate<'tcx>} nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>} nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>} nop_list_lift! {projs; ProjectionKind => ProjectionKind} @@ -2109,7 +2108,7 @@ slice_interners!( substs: _intern_substs(GenericArg<'tcx>), canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo<'tcx>), poly_existential_predicates: - _intern_poly_existential_predicates(ty::Binder<'tcx, ExistentialPredicate<'tcx>>), + _intern_poly_existential_predicates(ty::ExistentialPredicate<'tcx>), predicates: _intern_predicates(Predicate<'tcx>), projs: _intern_projs(ProjectionKind), place_elems: _intern_place_elems(PlaceElem<'tcx>), @@ -2372,7 +2371,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_dynamic( self, - obj: &'tcx List>>, + obj: &'tcx List>, reg: ty::Region<'tcx>, ) -> Ty<'tcx> { self.mk_ty(Dynamic(obj, reg)) @@ -2504,8 +2503,8 @@ impl<'tcx> TyCtxt<'tcx> { pub fn intern_poly_existential_predicates( self, - eps: &[ty::Binder<'tcx, ExistentialPredicate<'tcx>>], - ) -> &'tcx List>> { + eps: &[ty::ExistentialPredicate<'tcx>], + ) -> &'tcx List> { assert!(!eps.is_empty()); assert!( eps.array_windows() @@ -2577,10 +2576,7 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn mk_poly_existential_predicates< - I: InternAs< - [ty::Binder<'tcx, ExistentialPredicate<'tcx>>], - &'tcx List>>, - >, + I: InternAs<[ExistentialPredicate<'tcx>], &'tcx List>>, >( self, iter: I, diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index b14a69892657b..8dd9e45b09d3c 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -62,9 +62,7 @@ pub enum TypeError<'tcx> { CyclicTy(Ty<'tcx>), CyclicConst(&'tcx ty::Const<'tcx>), ProjectionMismatched(ExpectedFound), - ExistentialMismatch( - ExpectedFound<&'tcx ty::List>>>, - ), + ExistentialMismatch(ExpectedFound<&'tcx ty::List>>), ObjectUnsafeCoercion(DefId), ConstMismatch(ExpectedFound<&'tcx ty::Const<'tcx>>), diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index a078b6fb742a7..29d263b873408 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -174,11 +174,11 @@ impl FlagComputation { &ty::Dynamic(obj, r) => { for predicate in obj.iter() { self.bound_computation(predicate, |computation, predicate| match predicate { - ty::ExistentialPredicate::Trait(tr) => computation.add_substs(tr.substs), - ty::ExistentialPredicate::Projection(p) => { + ty::WhereClause::Trait(tr) => computation.add_substs(tr.substs), + ty::WhereClause::Projection(p) => { computation.add_existential_projection(&p); } - ty::ExistentialPredicate::AutoTrait(_) => {} + ty::WhereClause::AutoTrait(_) => {} }); } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 673733faa766f..ebb582d738f14 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -77,7 +77,7 @@ pub use self::sty::{ GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, ProjectionTy, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, - UpvarSubsts, VarianceDiagInfo, VarianceDiagMutKind, + UpvarSubsts, VarianceDiagInfo, VarianceDiagMutKind, WhereClause, }; pub use self::trait_def::TraitDef; diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 308b4d2fefc71..20e331f122612 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -63,7 +63,7 @@ pub trait Printer<'tcx>: Sized { fn print_dyn_existential( self, - predicates: &'tcx ty::List>>, + predicates: &'tcx ty::List>, ) -> Result; fn print_const(self, ct: &'tcx ty::Const<'tcx>) -> Result; @@ -345,9 +345,7 @@ impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for Ty<'tcx> { } } -impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> - for &'tcx ty::List>> -{ +impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for &'tcx ty::List> { type Output = P::DynExistential; type Error = P::Error; fn print(&self, cx: P) -> Result { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 5d9e7aaf72f8e..35442be56226a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -800,7 +800,7 @@ pub trait PrettyPrinter<'tcx>: fn pretty_print_dyn_existential( mut self, - predicates: &'tcx ty::List>>, + predicates: &'tcx ty::List>, ) -> Result { // Generate the main trait ref, including associated types. let mut first = true; @@ -1484,7 +1484,7 @@ impl Printer<'tcx> for FmtPrinter<'_, 'tcx, F> { fn print_dyn_existential( self, - predicates: &'tcx ty::List>>, + predicates: &'tcx ty::List>, ) -> Result { self.pretty_print_dyn_existential(predicates) } @@ -2210,12 +2210,12 @@ impl ty::Binder<'tcx, ty::TraitRef<'tcx>> { forward_display_to_print! { Ty<'tcx>, - &'tcx ty::List>>, + &'tcx ty::List>, &'tcx ty::Const<'tcx>, // HACK(eddyb) these are exhaustive instead of generic, // because `for<'tcx>` isn't possible yet. - ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>, + ty::Binder<'tcx, ty::WhereClause<'tcx>>, ty::Binder<'tcx, ty::TraitRef<'tcx>>, ty::Binder<'tcx, ty::ExistentialTraitRef<'tcx>>, ty::Binder<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>, @@ -2254,11 +2254,11 @@ define_print_and_forward_display! { p!(write("{} = ", name), print(self.ty)) } - ty::ExistentialPredicate<'tcx> { + ty::WhereClause<'tcx> { match *self { - ty::ExistentialPredicate::Trait(x) => p!(print(x)), - ty::ExistentialPredicate::Projection(x) => p!(print(x)), - ty::ExistentialPredicate::AutoTrait(def_id) => { + ty::WhereClause::Trait(x) => p!(print(x)), + ty::WhereClause::Projection(x) => p!(print(x)), + ty::WhereClause::AutoTrait(def_id) => { p!(print_def_path(def_id, &[])); } } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index c7d8bec506f6b..8b34bf76e1784 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -672,7 +672,7 @@ fn check_const_value_eq>( }) } -impl<'tcx> Relate<'tcx> for &'tcx ty::List>> { +impl<'tcx> Relate<'tcx> for &'tcx ty::List> { fn relate>( relation: &mut R, a: Self, @@ -695,7 +695,7 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List Ok(ep_a .rebind(Trait(relation.relate(ep_a.rebind(a), ep_b.rebind(b))?.skip_binder()))), diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 0f8e80806e31e..608d349b5c547 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -347,17 +347,13 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> { } } -impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> { - type Lifted = ty::ExistentialPredicate<'tcx>; +impl<'a, 'tcx> Lift<'tcx> for ty::WhereClause<'a> { + type Lifted = ty::WhereClause<'tcx>; fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option { match self { - ty::ExistentialPredicate::Trait(x) => tcx.lift(x).map(ty::ExistentialPredicate::Trait), - ty::ExistentialPredicate::Projection(x) => { - tcx.lift(x).map(ty::ExistentialPredicate::Projection) - } - ty::ExistentialPredicate::AutoTrait(def_id) => { - Some(ty::ExistentialPredicate::AutoTrait(def_id)) - } + ty::WhereClause::Trait(x) => tcx.lift(x).map(ty::WhereClause::Trait), + ty::WhereClause::Projection(x) => tcx.lift(x).map(ty::WhereClause::Projection), + ty::WhereClause::AutoTrait(def_id) => Some(ty::WhereClause::AutoTrait(def_id)), } } } @@ -787,7 +783,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<'tcx, T> { } } -impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List>> { +impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { fn super_fold_with>(self, folder: &mut F) -> Self { ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v)) } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index e57075ed33811..57d406d0e2c88 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -150,7 +150,7 @@ pub enum TyKind<'tcx> { FnPtr(PolyFnSig<'tcx>), /// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`. - Dynamic(&'tcx List>>, ty::Region<'tcx>), + Dynamic(&'tcx List>, ty::Region<'tcx>), /// The anonymous type of a closure. Used to represent the type of /// `|a| a`. @@ -766,7 +766,7 @@ impl<'tcx> InlineConstSubsts<'tcx> { #[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] -pub enum ExistentialPredicate<'tcx> { +pub enum WhereClause<'tcx> { /// E.g., `Iterator`. Trait(ExistentialTraitRef<'tcx>), /// E.g., `Iterator::Item = T`. @@ -775,11 +775,13 @@ pub enum ExistentialPredicate<'tcx> { AutoTrait(DefId), } -impl<'tcx> ExistentialPredicate<'tcx> { +pub type ExistentialPredicate<'tcx> = Binder<'tcx, WhereClause<'tcx>>; + +impl<'tcx> WhereClause<'tcx> { /// Compares via an ordering that will not change if modules are reordered or other changes are /// made to the tree. In particular, this ordering is preserved across incremental compilations. pub fn stable_cmp(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Ordering { - use self::ExistentialPredicate::*; + use WhereClause::*; match (*self, *other) { (Trait(_), Trait(_)) => Ordering::Equal, (Projection(ref a), Projection(ref b)) => { @@ -796,17 +798,17 @@ impl<'tcx> ExistentialPredicate<'tcx> { } } -impl<'tcx> Binder<'tcx, ExistentialPredicate<'tcx>> { +impl<'tcx> ExistentialPredicate<'tcx> { pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicate<'tcx> { use crate::ty::ToPredicate; match self.skip_binder() { - ExistentialPredicate::Trait(tr) => { + WhereClause::Trait(tr) => { self.rebind(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx) } - ExistentialPredicate::Projection(p) => { + WhereClause::Projection(p) => { self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx) } - ExistentialPredicate::AutoTrait(did) => { + WhereClause::AutoTrait(did) => { let trait_ref = self.rebind(ty::TraitRef { def_id: did, substs: tcx.mk_substs_trait(self_ty, &[]), @@ -817,7 +819,7 @@ impl<'tcx> Binder<'tcx, ExistentialPredicate<'tcx>> { } } -impl<'tcx> List>> { +impl<'tcx> List> { /// Returns the "principal `DefId`" of this set of existential predicates. /// /// A Rust trait object type consists (in addition to a lifetime bound) @@ -846,7 +848,7 @@ impl<'tcx> List>> { pub fn principal(&self) -> Option>> { self[0] .map_bound(|this| match this { - ExistentialPredicate::Trait(tr) => Some(tr), + WhereClause::Trait(tr) => Some(tr), _ => None, }) .transpose() @@ -863,7 +865,7 @@ impl<'tcx> List>> { self.iter().filter_map(|predicate| { predicate .map_bound(|pred| match pred { - ExistentialPredicate::Projection(projection) => Some(projection), + WhereClause::Projection(projection) => Some(projection), _ => None, }) .transpose() @@ -873,7 +875,7 @@ impl<'tcx> List>> { #[inline] pub fn auto_traits<'a>(&'a self) -> impl Iterator + 'a { self.iter().filter_map(|predicate| match predicate.skip_binder() { - ExistentialPredicate::AutoTrait(did) => Some(did), + WhereClause::AutoTrait(did) => Some(did), _ => None, }) } @@ -961,20 +963,13 @@ pub struct ExistentialTraitRef<'tcx> { pub substs: SubstsRef<'tcx>, } -impl<'tcx> ExistentialTraitRef<'tcx> { - pub fn erase_self_ty( - tcx: TyCtxt<'tcx>, - trait_ref: ty::TraitRef<'tcx>, - ) -> ty::ExistentialTraitRef<'tcx> { - // Assert there is a Self. - trait_ref.substs.type_at(0); - - ty::ExistentialTraitRef { - def_id: trait_ref.def_id, - substs: tcx.intern_substs(&trait_ref.substs[1..]), - } +impl From> for ExistentialTraitRef<'tcx> { + fn from(trait_ref: TraitRef<'tcx>) -> Self { + Self { def_id: trait_ref.def_id, substs: trait_ref.substs } } +} +impl<'tcx> ExistentialTraitRef<'tcx> { /// Object types don't have a self type specified. Therefore, when /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` @@ -1530,6 +1525,16 @@ pub struct ExistentialProjection<'tcx> { pub ty: Ty<'tcx>, } +impl From> for ExistentialProjection<'tcx> { + fn from(projection_predicate: ty::ProjectionPredicate<'tcx>) -> Self { + Self { + item_def_id: projection_predicate.projection_ty.item_def_id, + substs: projection_predicate.projection_ty.substs, + ty: projection_predicate.ty, + } + } +} + pub type PolyExistentialProjection<'tcx> = Binder<'tcx, ExistentialProjection<'tcx>>; impl<'tcx> ExistentialProjection<'tcx> { @@ -1560,20 +1565,6 @@ impl<'tcx> ExistentialProjection<'tcx> { ty: self.ty, } } - - pub fn erase_self_ty( - tcx: TyCtxt<'tcx>, - projection_predicate: ty::ProjectionPredicate<'tcx>, - ) -> Self { - // Assert there is a Self. - projection_predicate.projection_ty.substs.type_at(0); - - Self { - item_def_id: projection_predicate.projection_ty.item_def_id, - substs: tcx.intern_substs(&projection_predicate.projection_ty.substs[1..]), - ty: projection_predicate.ty, - } - } } impl<'tcx> PolyExistentialProjection<'tcx> { diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs index f766cad2b3d21..7e69740a071c3 100644 --- a/compiler/rustc_middle/src/ty/vtable.rs +++ b/compiler/rustc_middle/src/ty/vtable.rs @@ -76,7 +76,6 @@ pub(super) fn vtable_allocation_provider<'tcx>( // No need to do any alignment checks on the memory accesses below, because we know the // allocation is correctly aligned as we created it above. Also we're only offsetting by // multiples of `ptr_align`, which means that it will stay aligned to `ptr_align`. - for (idx, entry) in vtable_entries.iter().enumerate() { let idx: u64 = u64::try_from(idx).unwrap(); let scalar = match entry { @@ -97,8 +96,7 @@ pub(super) fn vtable_allocation_provider<'tcx>( ScalarMaybeUninit::from_pointer(fn_ptr, &tcx) } VtblEntry::TraitVPtr(trait_ref) => { - let super_trait_ref = trait_ref - .map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)); + let super_trait_ref = trait_ref.map_bound(|trait_ref| trait_ref.into()); let supertrait_alloc_id = tcx.vtable_allocation((ty, Some(super_trait_ref))); let vptr = Pointer::from(supertrait_alloc_id); ScalarMaybeUninit::from_pointer(vptr, &tcx) diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 73985cf31e0f9..769cc550f62cd 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -171,9 +171,9 @@ fn push_inner<'tcx>( stack.push(lt.into()); stack.extend(obj.iter().rev().flat_map(|predicate| { let (substs, opt_ty) = match predicate.skip_binder() { - ty::ExistentialPredicate::Trait(tr) => (tr.substs, None), - ty::ExistentialPredicate::Projection(p) => (p.substs, Some(p.ty)), - ty::ExistentialPredicate::AutoTrait(_) => + ty::WhereClause::Trait(tr) => (tr.substs, None), + ty::WhereClause::Projection(p) => (p.substs, Some(p.ty)), + ty::WhereClause::AutoTrait(_) => // Empty iterator { (ty::InternalSubsts::empty(), None) diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 11668146f7b10..bbea6ca0ba3fd 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -229,9 +229,9 @@ where // and are visited by shallow visitors. for predicate in predicates { let trait_ref = match predicate.skip_binder() { - ty::ExistentialPredicate::Trait(trait_ref) => trait_ref, - ty::ExistentialPredicate::Projection(proj) => proj.trait_ref(tcx), - ty::ExistentialPredicate::AutoTrait(def_id) => { + ty::WhereClause::Trait(trait_ref) => trait_ref, + ty::WhereClause::Projection(proj) => proj.trait_ref(tcx), + ty::WhereClause::AutoTrait(def_id) => { ty::ExistentialTraitRef { def_id, substs: InternalSubsts::empty() } } }; diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index de18614360ef5..6e19c1d13a89c 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -230,7 +230,7 @@ impl Printer<'tcx> for &mut SymbolPrinter<'tcx> { fn print_dyn_existential( mut self, - predicates: &'tcx ty::List>>, + predicates: &'tcx ty::List>, ) -> Result { let mut first = true; for p in predicates { diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 0363ddb0e6eee..a3d546814445b 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -515,7 +515,7 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> { fn print_dyn_existential( mut self, - predicates: &'tcx ty::List>>, + predicates: &'tcx ty::List>, ) -> Result { // Okay, so this is a bit tricky. Imagine we have a trait object like // `dyn for<'a> Foo<'a, Bar = &'a ()>`. When we mangle this, the @@ -550,19 +550,19 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> { // because of HRTBs (only in the `Self` type). Also, auto traits // could have different bound vars *anyways*. match predicate.as_ref().skip_binder() { - ty::ExistentialPredicate::Trait(trait_ref) => { + ty::WhereClause::Trait(trait_ref) => { // Use a type that can't appear in defaults of type parameters. let dummy_self = cx.tcx.mk_ty_infer(ty::FreshTy(0)); let trait_ref = trait_ref.with_self_ty(cx.tcx, dummy_self); cx = cx.print_def_path(trait_ref.def_id, trait_ref.substs)?; } - ty::ExistentialPredicate::Projection(projection) => { + ty::WhereClause::Projection(projection) => { let name = cx.tcx.associated_item(projection.item_def_id).ident; cx.push("p"); cx.push_ident(&name.as_str()); cx = projection.ty.print(cx)?; } - ty::ExistentialPredicate::AutoTrait(def_id) => { + ty::WhereClause::AutoTrait(def_id) => { cx = cx.print_def_path(*def_id, &[])?; } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 6128c119b6b76..7ea9a60bd85b4 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -221,7 +221,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } if let ty::Dynamic(traits, _) = self_ty.kind() { for t in traits.iter() { - if let ty::ExistentialPredicate::Trait(trait_ref) = t.skip_binder() { + if let ty::WhereClause::Trait(trait_ref) = t.skip_binder() { flags.push((sym::_Self, Some(self.tcx.def_path_str(trait_ref.def_id)))) } } diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index d4a586b0124a2..f7dd7d10576e1 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -675,8 +675,7 @@ fn vtable_entries<'tcx>( entries.extend(COMMON_VTABLE_ENTRIES); } VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => { - let existential_trait_ref = trait_ref - .map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)); + let existential_trait_ref = trait_ref.map_bound(|trait_ref| trait_ref.into()); // Lookup the shape of vtable for the trait. let own_existential_entries = diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index afc546540d2e2..19f8cac9361e0 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -554,9 +554,7 @@ fn object_ty_for_trait<'tcx>( let trait_ref = ty::TraitRef::identity(tcx, trait_def_id); - let trait_predicate = trait_ref.map_bound(|trait_ref| { - ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)) - }); + let trait_predicate = trait_ref.map_bound(|trait_ref| ty::WhereClause::Trait(trait_ref.into())); let mut associated_types = traits::supertraits(tcx, trait_ref) .flat_map(|super_trait_ref| { @@ -574,7 +572,7 @@ fn object_ty_for_trait<'tcx>( // We *can* get bound lifetimes here in cases like // `trait MyTrait: for<'s> OtherTrait<&'s T, Output=bool>`. super_trait_ref.map_bound(|super_trait_ref| { - ty::ExistentialPredicate::Projection(ty::ExistentialProjection { + ty::WhereClause::Projection(ty::ExistentialProjection { ty: tcx.mk_projection(item.def_id, super_trait_ref.substs), item_def_id: item.def_id, substs: super_trait_ref.substs, diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 2f1f7971a7926..3b66082c15a47 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -736,23 +736,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { source_trait_ref = principal_a.with_self_ty(tcx, source); upcast_trait_ref = util::supertraits(tcx, source_trait_ref).nth(idx).unwrap(); assert_eq!(data_b.principal_def_id(), Some(upcast_trait_ref.def_id())); - let existential_predicate = upcast_trait_ref.map_bound(|trait_ref| { - ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef::erase_self_ty( - tcx, trait_ref, - )) - }); + let existential_predicate = upcast_trait_ref + .map_bound(|trait_ref| ty::WhereClause::Trait(trait_ref.into())); let iter = Some(existential_predicate) .into_iter() .chain( data_a .projection_bounds() - .map(|b| b.map_bound(ty::ExistentialPredicate::Projection)), + .map(|b| b.map_bound(ty::WhereClause::Projection)), ) .chain( - data_b - .auto_traits() - .map(ty::ExistentialPredicate::AutoTrait) - .map(ty::Binder::dummy), + data_b.auto_traits().map(ty::WhereClause::AutoTrait).map(ty::Binder::dummy), ); let existential_predicates = tcx.mk_poly_existential_predicates(iter); let source_trait = tcx.mk_dynamic(existential_predicates, r_b); @@ -838,18 +832,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // We already checked the compatiblity of auto traits within `assemble_candidates_for_unsizing`. let iter = data_a .principal() - .map(|b| b.map_bound(ty::ExistentialPredicate::Trait)) + .map(|b| b.map_bound(ty::WhereClause::Trait)) .into_iter() .chain( data_a .projection_bounds() - .map(|b| b.map_bound(ty::ExistentialPredicate::Projection)), + .map(|b| b.map_bound(ty::WhereClause::Projection)), ) .chain( - data_b - .auto_traits() - .map(ty::ExistentialPredicate::AutoTrait) - .map(ty::Binder::dummy), + data_b.auto_traits().map(ty::WhereClause::AutoTrait).map(ty::Binder::dummy), ); let existential_predicates = tcx.mk_poly_existential_predicates(iter); let source_trait = tcx.mk_dynamic(existential_predicates, r_b); diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index ed49abbbedc92..d8f6ab33ba2ca 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -285,8 +285,7 @@ pub fn upcast_choices( /// that come from `trait_ref`, excluding its supertraits. Used in /// computing the vtable base for an upcast trait of a trait object. pub fn count_own_vtable_entries(tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) -> usize { - let existential_trait_ref = - trait_ref.map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)); + let existential_trait_ref = trait_ref.map_bound(|trait_ref| trait_ref.into()); let existential_trait_ref = tcx.erase_regions(existential_trait_ref); tcx.own_existential_vtable_entries(existential_trait_ref).len() } @@ -299,9 +298,7 @@ pub fn get_vtable_index_of_object_method( object: &super::ImplSourceObjectData<'tcx, N>, method_def_id: DefId, ) -> usize { - let existential_trait_ref = object - .upcast_trait_ref - .map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)); + let existential_trait_ref = object.upcast_trait_ref.map_bound(|trait_ref| trait_ref.into()); let existential_trait_ref = tcx.erase_regions(existential_trait_ref); // Count number of methods preceding the one we are selecting and // add them to the total offset. diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index cb47ba9c360da..3cc27ba7da68d 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -719,7 +719,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { fn from_object_ty( &mut self, ty: Ty<'tcx>, - data: &'tcx ty::List>>, + data: &'tcx ty::List>, region: ty::Region<'tcx>, ) { // Imagine a type like this: @@ -782,7 +782,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { /// `infer::required_region_bounds`, see that for more information. pub fn object_region_bounds<'tcx>( tcx: TyCtxt<'tcx>, - existential_predicates: &'tcx ty::List>>, + existential_predicates: &'tcx ty::List>, ) -> Vec> { // Since we don't actually *know* the self type for an object, // this "open(err)" serves as a kind of dummy standin -- basically @@ -790,7 +790,7 @@ pub fn object_region_bounds<'tcx>( let open_ty = tcx.mk_ty_infer(ty::FreshTy(0)); let predicates = existential_predicates.iter().filter_map(|predicate| { - if let ty::ExistentialPredicate::Projection(_) = predicate.skip_binder() { + if let ty::WhereClause::Projection(_) = predicate.skip_binder() { None } else { Some(predicate.with_self_ty(tcx, open_ty)) diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index e24f699adf6b3..c7d7896c2481a 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -606,7 +606,7 @@ impl<'tcx> LowerInto<'tcx, Option LowerInto<'tcx, chalk_ir::Binders>>> - for &'tcx ty::List>> + for &'tcx ty::List> { fn lower_into( self, @@ -629,7 +629,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders { + ty::WhereClause::Trait(ty::ExistentialTraitRef { def_id, substs }) => { chalk_ir::Binders::new( binders.clone(), chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef { @@ -641,7 +641,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders chalk_ir::Binders::new( + ty::WhereClause::Projection(predicate) => chalk_ir::Binders::new( binders.clone(), chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq { alias: chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { @@ -654,7 +654,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders chalk_ir::Binders::new( + ty::WhereClause::AutoTrait(def_id) => chalk_ir::Binders::new( binders.clone(), chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef { trait_id: chalk_ir::TraitId(def_id), diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index da751f2075399..a972e486369e7 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1458,7 +1458,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ), ); } - ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref) + trait_ref.into() }) }); let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| { @@ -1469,21 +1469,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { &format!("trait_ref_to_existential called on {:?} with non-dummy Self", b), ); } - ty::ExistentialProjection::erase_self_ty(tcx, b) + b.into() }) }); - let regular_trait_predicates = existential_trait_refs - .map(|trait_ref| trait_ref.map_bound(ty::ExistentialPredicate::Trait)); + let regular_trait_predicates = + existential_trait_refs.map(|trait_ref| trait_ref.map_bound(ty::WhereClause::Trait)); let auto_trait_predicates = auto_traits.into_iter().map(|trait_ref| { - ty::Binder::dummy(ty::ExistentialPredicate::AutoTrait(trait_ref.trait_ref().def_id())) + ty::Binder::dummy(ty::WhereClause::AutoTrait(trait_ref.trait_ref().def_id())) }); // N.b. principal, projections, auto traits // FIXME: This is actually wrong with multiple principals in regards to symbol mangling let mut v = regular_trait_predicates - .chain( - existential_projections.map(|x| x.map_bound(ty::ExistentialPredicate::Projection)), - ) + .chain(existential_projections.map(|x| x.map_bound(ty::WhereClause::Projection))) .chain(auto_trait_predicates) .collect::>(); v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder())); @@ -2570,7 +2568,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { fn compute_object_lifetime_bound( &self, span: Span, - existential_predicates: &'tcx ty::List>>, + existential_predicates: &'tcx ty::List>, ) -> Option> // if None, use the default { let tcx = self.tcx(); diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index 2910ce6de6899..d738bf3c097b7 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -520,7 +520,7 @@ pub fn check_must_not_suspend_ty<'tcx>( ty::Dynamic(binder, _) => { let mut has_emitted = false; for predicate in binder.iter() { - if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { + if let ty::WhereClause::Trait(ref trait_ref) = predicate.skip_binder() { let def_id = trait_ref.def_id; let descr_post = &format!(" trait object{}{}", plural_suffix, data.descr_post); if check_must_not_suspend_def( diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 71cd8a43329c5..67e4825483f82 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -715,11 +715,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Dynamic(preds, _) => { for pred in preds.iter() { match pred.skip_binder() { - ty::ExistentialPredicate::Trait(tr) => { + ty::WhereClause::Trait(tr) => { bound_spans.push((def_span(tr.def_id), msg.clone())) } - ty::ExistentialPredicate::Projection(_) - | ty::ExistentialPredicate::AutoTrait(_) => {} + ty::WhereClause::Projection(_) + | ty::WhereClause::AutoTrait(_) => {} } } } diff --git a/compiler/rustc_typeck/src/coherence/mod.rs b/compiler/rustc_typeck/src/coherence/mod.rs index 377ebf1fe2a9f..8ef5b1adcf940 100644 --- a/compiler/rustc_typeck/src/coherence/mod.rs +++ b/compiler/rustc_typeck/src/coherence/mod.rs @@ -229,11 +229,11 @@ fn check_object_overlap<'tcx>( let component_def_ids = data.iter().flat_map(|predicate| { match predicate.skip_binder() { - ty::ExistentialPredicate::Trait(tr) => Some(tr.def_id), - ty::ExistentialPredicate::AutoTrait(def_id) => Some(def_id), + ty::WhereClause::Trait(tr) => Some(tr.def_id), + ty::WhereClause::AutoTrait(def_id) => Some(def_id), // An associated type projection necessarily comes with // an additional `Trait` requirement. - ty::ExistentialPredicate::Projection(..) => None, + ty::WhereClause::Projection(..) => None, } }); diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index e6d8ba3f02eb0..21979ef4281a4 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -106,7 +106,7 @@ fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { ty::Dynamic(preds, _) => { for pred in preds.iter() { match pred.skip_binder() { - ty::ExistentialPredicate::AutoTrait(_) | ty::ExistentialPredicate::Projection(_) => { + ty::WhereClause::AutoTrait(_) | ty::WhereClause::Projection(_) => { return Err(( span, "trait bounds other than `Sized` \ @@ -114,7 +114,7 @@ fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { .into(), )); }, - ty::ExistentialPredicate::Trait(trait_ref) => { + ty::WhereClause::Trait(trait_ref) => { if Some(trait_ref.def_id) != tcx.lang_items().sized_trait() { return Err(( span, diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index ca64ac7de3eea..321c6f00ba101 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -167,7 +167,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { }, ty::Dynamic(binder, _) => { for predicate in binder.iter() { - if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { + if let ty::WhereClause::Trait(ref trait_ref) = predicate.skip_binder() { if must_use_attr(cx.tcx.get_attrs(trait_ref.def_id)).is_some() { return true; }