@@ -485,8 +485,22 @@ pub enum PredicateKind<'tcx> {
485
485
ClosureKind ( DefId , SubstsRef < ' tcx > , ClosureKind ) ,
486
486
487
487
/// `T1 <: T2`
488
+ ///
489
+ /// This obligation is created most often when we have two
490
+ /// unresolved type variables and hence don't have enough
491
+ /// information to process the subtyping obligation yet.
488
492
Subtype ( SubtypePredicate < ' tcx > ) ,
489
493
494
+ /// `T1` coerced to `T2`
495
+ ///
496
+ /// Like a subtyping obligation, this is created most often
497
+ /// when we have two unresolved type variables and hence
498
+ /// don't have enough information to process the coercion
499
+ /// obligation yet. At the moment, we actually process coercions
500
+ /// very much like subtyping and don't handle the full coercion
501
+ /// logic.
502
+ Coerce ( CoercePredicate < ' tcx > ) ,
503
+
490
504
/// Constant initializer must evaluate successfully.
491
505
ConstEvaluatable ( ty:: WithOptConstParam < DefId > , SubstsRef < ' tcx > ) ,
492
506
@@ -655,6 +669,9 @@ pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate<Ty<'tcx>, ty::Region<'t
655
669
pub type PolyRegionOutlivesPredicate < ' tcx > = ty:: Binder < ' tcx , RegionOutlivesPredicate < ' tcx > > ;
656
670
pub type PolyTypeOutlivesPredicate < ' tcx > = ty:: Binder < ' tcx , TypeOutlivesPredicate < ' tcx > > ;
657
671
672
+ /// Encodes that `a` must be a subtype of `b`. The `a_is_expected` flag indicates
673
+ /// whether the `a` type is the type that we should label as "expected" when
674
+ /// presenting user diagnostics.
658
675
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug , TyEncodable , TyDecodable ) ]
659
676
#[ derive( HashStable , TypeFoldable ) ]
660
677
pub struct SubtypePredicate < ' tcx > {
@@ -664,6 +681,15 @@ pub struct SubtypePredicate<'tcx> {
664
681
}
665
682
pub type PolySubtypePredicate < ' tcx > = ty:: Binder < ' tcx , SubtypePredicate < ' tcx > > ;
666
683
684
+ /// Encodes that we have to coerce *from* the `a` type to the `b` type.
685
+ #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug , TyEncodable , TyDecodable ) ]
686
+ #[ derive( HashStable , TypeFoldable ) ]
687
+ pub struct CoercePredicate < ' tcx > {
688
+ pub a : Ty < ' tcx > ,
689
+ pub b : Ty < ' tcx > ,
690
+ }
691
+ pub type PolyCoercePredicate < ' tcx > = ty:: Binder < ' tcx , CoercePredicate < ' tcx > > ;
692
+
667
693
/// This kind of predicate has no *direct* correspondent in the
668
694
/// syntax, but it roughly corresponds to the syntactic forms:
669
695
///
@@ -806,6 +832,7 @@ impl<'tcx> Predicate<'tcx> {
806
832
}
807
833
PredicateKind :: Projection ( ..)
808
834
| PredicateKind :: Subtype ( ..)
835
+ | PredicateKind :: Coerce ( ..)
809
836
| PredicateKind :: RegionOutlives ( ..)
810
837
| PredicateKind :: WellFormed ( ..)
811
838
| PredicateKind :: ObjectSafe ( ..)
@@ -824,6 +851,7 @@ impl<'tcx> Predicate<'tcx> {
824
851
PredicateKind :: Trait ( ..)
825
852
| PredicateKind :: Projection ( ..)
826
853
| PredicateKind :: Subtype ( ..)
854
+ | PredicateKind :: Coerce ( ..)
827
855
| PredicateKind :: RegionOutlives ( ..)
828
856
| PredicateKind :: WellFormed ( ..)
829
857
| PredicateKind :: ObjectSafe ( ..)
0 commit comments