11use rustc_data_structures:: captures:: Captures ;
22use rustc_data_structures:: intern:: Interned ;
3- use rustc_errors:: { DiagArgValue , IntoDiagArg } ;
43use rustc_hir:: def_id:: DefId ;
54use rustc_macros:: { HashStable , Lift , TyDecodable , TyEncodable , TypeFoldable , TypeVisitable } ;
65use rustc_type_ir:: ClauseKind as IrClauseKind ;
76use rustc_type_ir:: PredicateKind as IrPredicateKind ;
87use rustc_type_ir:: TraitPredicate as IrTraitPredicate ;
98use rustc_type_ir:: TraitRef as IrTraitRef ;
9+ use rustc_type_ir:: ProjectionPredicate as IrProjectionPredicate ;
10+ use rustc_type_ir:: ExistentialTraitRef as IrExistentialTraitRef ;
11+ use rustc_type_ir:: ExistentialProjection as IrExistentialProjection ;
1012use std:: cmp:: Ordering ;
1113
12- use crate :: ty:: visit:: TypeVisitableExt ;
1314use crate :: ty:: {
14- self , AliasTy , Binder , DebruijnIndex , DebugWithInfcx , EarlyBinder , GenericArgsRef ,
15+ self , AliasTy , Binder , DebruijnIndex , DebugWithInfcx , EarlyBinder ,
1516 PredicatePolarity , Term , Ty , TyCtxt , TypeFlags , WithCachedTypeInfo ,
1617} ;
1718
1819pub type TraitRef < ' tcx > = IrTraitRef < TyCtxt < ' tcx > > ;
20+ pub type ProjectionPredicate < ' tcx > = IrProjectionPredicate < TyCtxt < ' tcx > > ;
21+ pub type ExistentialTraitRef < ' tcx > = IrExistentialTraitRef < TyCtxt < ' tcx > > ;
22+ pub type ExistentialProjection < ' tcx > = IrExistentialProjection < TyCtxt < ' tcx > > ;
1923pub type TraitPredicate < ' tcx > = IrTraitPredicate < TyCtxt < ' tcx > > ;
2024pub type ClauseKind < ' tcx > = IrClauseKind < TyCtxt < ' tcx > > ;
2125pub type PredicateKind < ' tcx > = IrPredicateKind < TyCtxt < ' tcx > > ;
@@ -342,52 +346,6 @@ impl<'tcx> PolyTraitRef<'tcx> {
342346 }
343347}
344348
345- /// An existential reference to a trait, where `Self` is erased.
346- /// For example, the trait object `Trait<'a, 'b, X, Y>` is:
347- /// ```ignore (illustrative)
348- /// exists T. T: Trait<'a, 'b, X, Y>
349- /// ```
350- /// The generic parameters don't include the erased `Self`, only trait
351- /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above).
352- #[ derive( Copy , Clone , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
353- #[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
354- pub struct ExistentialTraitRef < ' tcx > {
355- pub def_id : DefId ,
356- pub args : GenericArgsRef < ' tcx > ,
357- }
358-
359- impl < ' tcx > ExistentialTraitRef < ' tcx > {
360- pub fn erase_self_ty (
361- tcx : TyCtxt < ' tcx > ,
362- trait_ref : ty:: TraitRef < ' tcx > ,
363- ) -> ty:: ExistentialTraitRef < ' tcx > {
364- // Assert there is a Self.
365- trait_ref. args . type_at ( 0 ) ;
366-
367- ty:: ExistentialTraitRef {
368- def_id : trait_ref. def_id ,
369- args : tcx. mk_args ( & trait_ref. args [ 1 ..] ) ,
370- }
371- }
372-
373- /// Object types don't have a self type specified. Therefore, when
374- /// we convert the principal trait-ref into a normal trait-ref,
375- /// you must give *some* self type. A common choice is `mk_err()`
376- /// or some placeholder type.
377- pub fn with_self_ty ( & self , tcx : TyCtxt < ' tcx > , self_ty : Ty < ' tcx > ) -> ty:: TraitRef < ' tcx > {
378- // otherwise the escaping vars would be captured by the binder
379- // debug_assert!(!self_ty.has_escaping_bound_vars());
380-
381- ty:: TraitRef :: new ( tcx, self . def_id , [ self_ty. into ( ) ] . into_iter ( ) . chain ( self . args . iter ( ) ) )
382- }
383- }
384-
385- impl < ' tcx > IntoDiagArg for ExistentialTraitRef < ' tcx > {
386- fn into_diag_arg ( self ) -> DiagArgValue {
387- self . to_string ( ) . into_diag_arg ( )
388- }
389- }
390-
391349pub type PolyExistentialTraitRef < ' tcx > = ty:: Binder < ' tcx , ExistentialTraitRef < ' tcx > > ;
392350
393351impl < ' tcx > PolyExistentialTraitRef < ' tcx > {
@@ -404,62 +362,8 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
404362 }
405363}
406364
407- /// A `ProjectionPredicate` for an `ExistentialTraitRef`.
408- #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug , TyEncodable , TyDecodable ) ]
409- #[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
410- pub struct ExistentialProjection < ' tcx > {
411- pub def_id : DefId ,
412- pub args : GenericArgsRef < ' tcx > ,
413- pub term : Term < ' tcx > ,
414- }
415-
416365pub type PolyExistentialProjection < ' tcx > = ty:: Binder < ' tcx , ExistentialProjection < ' tcx > > ;
417366
418- impl < ' tcx > ExistentialProjection < ' tcx > {
419- /// Extracts the underlying existential trait reference from this projection.
420- /// For example, if this is a projection of `exists T. <T as Iterator>::Item == X`,
421- /// then this function would return an `exists T. T: Iterator` existential trait
422- /// reference.
423- pub fn trait_ref ( & self , tcx : TyCtxt < ' tcx > ) -> ty:: ExistentialTraitRef < ' tcx > {
424- let def_id = tcx. parent ( self . def_id ) ;
425- let args_count = tcx. generics_of ( def_id) . count ( ) - 1 ;
426- let args = tcx. mk_args ( & self . args [ ..args_count] ) ;
427- ty:: ExistentialTraitRef { def_id, args }
428- }
429-
430- pub fn with_self_ty (
431- & self ,
432- tcx : TyCtxt < ' tcx > ,
433- self_ty : Ty < ' tcx > ,
434- ) -> ty:: ProjectionPredicate < ' tcx > {
435- // otherwise the escaping regions would be captured by the binders
436- debug_assert ! ( !self_ty. has_escaping_bound_vars( ) ) ;
437-
438- ty:: ProjectionPredicate {
439- projection_ty : AliasTy :: new (
440- tcx,
441- self . def_id ,
442- [ self_ty. into ( ) ] . into_iter ( ) . chain ( self . args ) ,
443- ) ,
444- term : self . term ,
445- }
446- }
447-
448- pub fn erase_self_ty (
449- tcx : TyCtxt < ' tcx > ,
450- projection_predicate : ty:: ProjectionPredicate < ' tcx > ,
451- ) -> Self {
452- // Assert there is a Self.
453- projection_predicate. projection_ty . args . type_at ( 0 ) ;
454-
455- Self {
456- def_id : projection_predicate. projection_ty . def_id ,
457- args : tcx. mk_args ( & projection_predicate. projection_ty . args [ 1 ..] ) ,
458- term : projection_predicate. term ,
459- }
460- }
461- }
462-
463367impl < ' tcx > PolyExistentialProjection < ' tcx > {
464368 pub fn with_self_ty (
465369 & self ,
@@ -628,43 +532,6 @@ pub struct CoercePredicate<'tcx> {
628532}
629533pub type PolyCoercePredicate < ' tcx > = ty:: Binder < ' tcx , CoercePredicate < ' tcx > > ;
630534
631- /// This kind of predicate has no *direct* correspondent in the
632- /// syntax, but it roughly corresponds to the syntactic forms:
633- ///
634- /// 1. `T: TraitRef<..., Item = Type>`
635- /// 2. `<T as TraitRef<...>>::Item == Type` (NYI)
636- ///
637- /// In particular, form #1 is "desugared" to the combination of a
638- /// normal trait predicate (`T: TraitRef<...>`) and one of these
639- /// predicates. Form #2 is a broader form in that it also permits
640- /// equality between arbitrary types. Processing an instance of
641- /// Form #2 eventually yields one of these `ProjectionPredicate`
642- /// instances to normalize the LHS.
643- #[ derive( Copy , Clone , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
644- #[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
645- pub struct ProjectionPredicate < ' tcx > {
646- pub projection_ty : AliasTy < ' tcx > ,
647- pub term : Term < ' tcx > ,
648- }
649-
650- impl < ' tcx > ProjectionPredicate < ' tcx > {
651- pub fn self_ty ( self ) -> Ty < ' tcx > {
652- self . projection_ty . self_ty ( )
653- }
654-
655- pub fn with_self_ty ( self , tcx : TyCtxt < ' tcx > , self_ty : Ty < ' tcx > ) -> ProjectionPredicate < ' tcx > {
656- Self { projection_ty : self . projection_ty . with_self_ty ( tcx, self_ty) , ..self }
657- }
658-
659- pub fn trait_def_id ( self , tcx : TyCtxt < ' tcx > ) -> DefId {
660- self . projection_ty . trait_def_id ( tcx)
661- }
662-
663- pub fn def_id ( self ) -> DefId {
664- self . projection_ty . def_id
665- }
666- }
667-
668535pub type PolyProjectionPredicate < ' tcx > = Binder < ' tcx , ProjectionPredicate < ' tcx > > ;
669536
670537impl < ' tcx > PolyProjectionPredicate < ' tcx > {
0 commit comments