1
1
use rustc_data_structures:: captures:: Captures ;
2
2
use rustc_data_structures:: intern:: Interned ;
3
- use rustc_errors:: { DiagArgValue , IntoDiagArg } ;
4
3
use rustc_hir:: def_id:: DefId ;
5
4
use rustc_macros:: { HashStable , Lift , TyDecodable , TyEncodable , TypeFoldable , TypeVisitable } ;
6
5
use rustc_type_ir:: ClauseKind as IrClauseKind ;
7
6
use rustc_type_ir:: PredicateKind as IrPredicateKind ;
8
7
use rustc_type_ir:: TraitPredicate as IrTraitPredicate ;
9
8
use 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 ;
10
12
use std:: cmp:: Ordering ;
11
13
12
- use crate :: ty:: visit:: TypeVisitableExt ;
13
14
use crate :: ty:: {
14
- self , AliasTy , Binder , DebruijnIndex , DebugWithInfcx , EarlyBinder , GenericArgsRef ,
15
+ self , AliasTy , Binder , DebruijnIndex , DebugWithInfcx , EarlyBinder ,
15
16
PredicatePolarity , Term , Ty , TyCtxt , TypeFlags , WithCachedTypeInfo ,
16
17
} ;
17
18
18
19
pub 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 > > ;
19
23
pub type TraitPredicate < ' tcx > = IrTraitPredicate < TyCtxt < ' tcx > > ;
20
24
pub type ClauseKind < ' tcx > = IrClauseKind < TyCtxt < ' tcx > > ;
21
25
pub type PredicateKind < ' tcx > = IrPredicateKind < TyCtxt < ' tcx > > ;
@@ -342,52 +346,6 @@ impl<'tcx> PolyTraitRef<'tcx> {
342
346
}
343
347
}
344
348
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
-
391
349
pub type PolyExistentialTraitRef < ' tcx > = ty:: Binder < ' tcx , ExistentialTraitRef < ' tcx > > ;
392
350
393
351
impl < ' tcx > PolyExistentialTraitRef < ' tcx > {
@@ -404,62 +362,8 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
404
362
}
405
363
}
406
364
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
-
416
365
pub type PolyExistentialProjection < ' tcx > = ty:: Binder < ' tcx , ExistentialProjection < ' tcx > > ;
417
366
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
-
463
367
impl < ' tcx > PolyExistentialProjection < ' tcx > {
464
368
pub fn with_self_ty (
465
369
& self ,
@@ -628,43 +532,6 @@ pub struct CoercePredicate<'tcx> {
628
532
}
629
533
pub type PolyCoercePredicate < ' tcx > = ty:: Binder < ' tcx , CoercePredicate < ' tcx > > ;
630
534
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
-
668
535
pub type PolyProjectionPredicate < ' tcx > = Binder < ' tcx , ProjectionPredicate < ' tcx > > ;
669
536
670
537
impl < ' tcx > PolyProjectionPredicate < ' tcx > {
0 commit comments