@@ -485,8 +485,22 @@ pub enum PredicateKind<'tcx> {
485485 ClosureKind ( DefId , SubstsRef < ' tcx > , ClosureKind ) ,
486486
487487 /// `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.
488492 Subtype ( SubtypePredicate < ' tcx > ) ,
489493
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+
490504 /// Constant initializer must evaluate successfully.
491505 ConstEvaluatable ( ty:: WithOptConstParam < DefId > , SubstsRef < ' tcx > ) ,
492506
@@ -655,6 +669,9 @@ pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate<Ty<'tcx>, ty::Region<'t
655669pub type PolyRegionOutlivesPredicate < ' tcx > = ty:: Binder < ' tcx , RegionOutlivesPredicate < ' tcx > > ;
656670pub type PolyTypeOutlivesPredicate < ' tcx > = ty:: Binder < ' tcx , TypeOutlivesPredicate < ' tcx > > ;
657671
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.
658675#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug , TyEncodable , TyDecodable ) ]
659676#[ derive( HashStable , TypeFoldable ) ]
660677pub struct SubtypePredicate < ' tcx > {
@@ -664,6 +681,15 @@ pub struct SubtypePredicate<'tcx> {
664681}
665682pub type PolySubtypePredicate < ' tcx > = ty:: Binder < ' tcx , SubtypePredicate < ' tcx > > ;
666683
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+
667693/// This kind of predicate has no *direct* correspondent in the
668694/// syntax, but it roughly corresponds to the syntactic forms:
669695///
@@ -806,6 +832,7 @@ impl<'tcx> Predicate<'tcx> {
806832 }
807833 PredicateKind :: Projection ( ..)
808834 | PredicateKind :: Subtype ( ..)
835+ | PredicateKind :: Coerce ( ..)
809836 | PredicateKind :: RegionOutlives ( ..)
810837 | PredicateKind :: WellFormed ( ..)
811838 | PredicateKind :: ObjectSafe ( ..)
@@ -824,6 +851,7 @@ impl<'tcx> Predicate<'tcx> {
824851 PredicateKind :: Trait ( ..)
825852 | PredicateKind :: Projection ( ..)
826853 | PredicateKind :: Subtype ( ..)
854+ | PredicateKind :: Coerce ( ..)
827855 | PredicateKind :: RegionOutlives ( ..)
828856 | PredicateKind :: WellFormed ( ..)
829857 | PredicateKind :: ObjectSafe ( ..)
0 commit comments