@@ -662,7 +662,7 @@ pub enum PredicateKind<'tcx> {
662662 /// `NormalizesTo(<T as Trait>::Assoc, ?x)` results in `NoSolution`.
663663 ///
664664 /// Only used in the new solver.
665- NormalizesTo ( ProjectionPredicate < ' tcx > ) ,
665+ NormalizesTo ( NormalizesTo < ' tcx > ) ,
666666
667667 /// Separate from `Clause::Projection` which is used for normalization in new solver.
668668 /// This predicate requires two terms to be equal to eachother.
@@ -1184,6 +1184,33 @@ impl<'tcx> PolyProjectionPredicate<'tcx> {
11841184 }
11851185}
11861186
1187+ /// Used by the new solver. Unlike a `ProjectionPredicate` this can only be
1188+ /// proven by actually normalizing `alias`.
1189+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
1190+ #[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
1191+ pub struct NormalizesTo < ' tcx > {
1192+ pub alias : AliasTy < ' tcx > ,
1193+ pub term : Term < ' tcx > ,
1194+ }
1195+
1196+ impl < ' tcx > NormalizesTo < ' tcx > {
1197+ pub fn self_ty ( self ) -> Ty < ' tcx > {
1198+ self . alias . self_ty ( )
1199+ }
1200+
1201+ pub fn with_self_ty ( self , tcx : TyCtxt < ' tcx > , self_ty : Ty < ' tcx > ) -> NormalizesTo < ' tcx > {
1202+ Self { alias : self . alias . with_self_ty ( tcx, self_ty) , ..self }
1203+ }
1204+
1205+ pub fn trait_def_id ( self , tcx : TyCtxt < ' tcx > ) -> DefId {
1206+ self . alias . trait_def_id ( tcx)
1207+ }
1208+
1209+ pub fn def_id ( self ) -> DefId {
1210+ self . alias . def_id
1211+ }
1212+ }
1213+
11871214pub trait ToPolyTraitRef < ' tcx > {
11881215 fn to_poly_trait_ref ( & self ) -> PolyTraitRef < ' tcx > ;
11891216}
@@ -1306,6 +1333,12 @@ impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
13061333 }
13071334}
13081335
1336+ impl < ' tcx > ToPredicate < ' tcx > for ProjectionPredicate < ' tcx > {
1337+ fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1338+ ty:: Binder :: dummy ( self ) . to_predicate ( tcx)
1339+ }
1340+ }
1341+
13091342impl < ' tcx > ToPredicate < ' tcx > for PolyProjectionPredicate < ' tcx > {
13101343 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
13111344 self . map_bound ( |p| PredicateKind :: Clause ( Clause :: Projection ( p) ) ) . to_predicate ( tcx)
@@ -1324,6 +1357,18 @@ impl<'tcx> ToPredicate<'tcx> for TraitPredicate<'tcx> {
13241357 }
13251358}
13261359
1360+ impl < ' tcx > ToPredicate < ' tcx > for NormalizesTo < ' tcx > {
1361+ fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1362+ PredicateKind :: NormalizesTo ( self ) . to_predicate ( tcx)
1363+ }
1364+ }
1365+
1366+ impl < ' tcx > ToPredicate < ' tcx > for ty:: Binder < ' tcx , NormalizesTo < ' tcx > > {
1367+ fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
1368+ self . map_bound ( |p| PredicateKind :: NormalizesTo ( p) ) . to_predicate ( tcx)
1369+ }
1370+ }
1371+
13271372impl < ' tcx > Predicate < ' tcx > {
13281373 pub fn to_opt_poly_trait_pred ( self ) -> Option < PolyTraitPredicate < ' tcx > > {
13291374 let predicate = self . kind ( ) ;
@@ -1395,7 +1440,8 @@ impl<'tcx> Predicate<'tcx> {
13951440 let predicate = self . kind ( ) ;
13961441 match predicate. skip_binder ( ) {
13971442 PredicateKind :: Clause ( clause) => Some ( predicate. rebind ( clause) ) ,
1398- PredicateKind :: AliasRelate ( ..)
1443+ PredicateKind :: NormalizesTo ( ..)
1444+ | PredicateKind :: AliasRelate ( ..)
13991445 | PredicateKind :: Subtype ( ..)
14001446 | PredicateKind :: Coerce ( ..)
14011447 | PredicateKind :: WellFormed ( ..)
0 commit comments