@@ -544,180 +544,182 @@ impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'tcx> {
544544 }
545545}
546546
547+ /// An `Into`-like trait that takes `TyCtxt` to perform interner-specific transformations.
547548pub trait Upcast < ' tcx , T > {
548549 fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> T ;
549550}
550551
551- impl < ' tcx , T > Upcast < ' tcx , T > for T {
552- fn upcast ( self , _tcx : TyCtxt < ' tcx > ) -> T {
553- self
552+ impl < ' tcx , T , U > Upcast < ' tcx , U > for T
553+ where
554+ U : UpcastFrom < ' tcx , T > ,
555+ {
556+ fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> U {
557+ U :: upcast_from ( self , tcx)
554558 }
555559}
556560
557- impl < ' tcx > Upcast < ' tcx , ty:: Predicate < ' tcx > > for PredicateKind < ' tcx > {
558- #[ inline( always) ]
559- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
560- ty:: Binder :: dummy ( self ) . upcast ( tcx)
561+ /// A `From`-like trait that takes `TyCtxt` to perform interner-specific transformations.
562+ pub trait UpcastFrom < ' tcx , T > {
563+ fn upcast_from ( from : T , tcx : TyCtxt < ' tcx > ) -> Self ;
564+ }
565+
566+ impl < ' tcx , T > UpcastFrom < ' tcx , T > for T {
567+ fn upcast_from ( from : T , _tcx : TyCtxt < ' tcx > ) -> Self {
568+ from
561569 }
562570}
563571
564- impl < ' tcx > Upcast < ' tcx , ty:: Predicate < ' tcx > > for Binder < ' tcx , PredicateKind < ' tcx > > {
565- #[ inline( always) ]
566- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
567- tcx. mk_predicate ( self )
572+ impl < ' tcx > UpcastFrom < ' tcx , PredicateKind < ' tcx > > for Predicate < ' tcx > {
573+ fn upcast_from ( from : PredicateKind < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
574+ ty:: Binder :: dummy ( from) . upcast ( tcx)
568575 }
569576}
570577
571- impl < ' tcx > Upcast < ' tcx , ty:: Predicate < ' tcx > > for ClauseKind < ' tcx > {
572- #[ inline( always) ]
573- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
574- tcx. mk_predicate ( ty:: Binder :: dummy ( ty:: PredicateKind :: Clause ( self ) ) )
578+ impl < ' tcx > UpcastFrom < ' tcx , Binder < ' tcx , PredicateKind < ' tcx > > > for Predicate < ' tcx > {
579+ fn upcast_from ( from : Binder < ' tcx , PredicateKind < ' tcx > > , tcx : TyCtxt < ' tcx > ) -> Self {
580+ tcx. mk_predicate ( from)
575581 }
576582}
577583
578- impl < ' tcx > Upcast < ' tcx , ty:: Predicate < ' tcx > > for Binder < ' tcx , ClauseKind < ' tcx > > {
579- #[ inline( always) ]
580- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
581- tcx. mk_predicate ( self . map_bound ( ty:: PredicateKind :: Clause ) )
584+ impl < ' tcx > UpcastFrom < ' tcx , ClauseKind < ' tcx > > for Predicate < ' tcx > {
585+ fn upcast_from ( from : ClauseKind < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
586+ tcx. mk_predicate ( ty:: Binder :: dummy ( PredicateKind :: Clause ( from) ) )
582587 }
583588}
584589
585- impl < ' tcx > Upcast < ' tcx , ty:: Predicate < ' tcx > > for Clause < ' tcx > {
586- #[ inline( always) ]
587- fn upcast ( self , _tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
588- self . as_predicate ( )
590+ impl < ' tcx > UpcastFrom < ' tcx , Binder < ' tcx , ClauseKind < ' tcx > > > for Predicate < ' tcx > {
591+ fn upcast_from ( from : Binder < ' tcx , ClauseKind < ' tcx > > , tcx : TyCtxt < ' tcx > ) -> Self {
592+ tcx. mk_predicate ( from. map_bound ( PredicateKind :: Clause ) )
589593 }
590594}
591595
592- impl < ' tcx > Upcast < ' tcx , Clause < ' tcx > > for ClauseKind < ' tcx > {
593- #[ inline( always) ]
594- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Clause < ' tcx > {
595- tcx. mk_predicate ( Binder :: dummy ( ty:: PredicateKind :: Clause ( self ) ) ) . expect_clause ( )
596+ impl < ' tcx > UpcastFrom < ' tcx , Clause < ' tcx > > for Predicate < ' tcx > {
597+ fn upcast_from ( from : Clause < ' tcx > , _tcx : TyCtxt < ' tcx > ) -> Self {
598+ from. as_predicate ( )
596599 }
597600}
598601
599- impl < ' tcx > Upcast < ' tcx , Clause < ' tcx > > for Binder < ' tcx , ClauseKind < ' tcx > > {
600- #[ inline( always) ]
601- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Clause < ' tcx > {
602- tcx. mk_predicate ( self . map_bound ( |clause| ty:: PredicateKind :: Clause ( clause) ) ) . expect_clause ( )
602+ impl < ' tcx > UpcastFrom < ' tcx , ClauseKind < ' tcx > > for Clause < ' tcx > {
603+ fn upcast_from ( from : ClauseKind < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
604+ tcx. mk_predicate ( Binder :: dummy ( PredicateKind :: Clause ( from) ) ) . expect_clause ( )
603605 }
604606}
605607
606- impl < ' tcx > Upcast < ' tcx , ty:: Predicate < ' tcx > > for TraitRef < ' tcx > {
607- #[ inline( always) ]
608- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
609- ty:: Binder :: dummy ( self ) . upcast ( tcx)
608+ impl < ' tcx > UpcastFrom < ' tcx , Binder < ' tcx , ClauseKind < ' tcx > > > for Clause < ' tcx > {
609+ fn upcast_from ( from : Binder < ' tcx , ClauseKind < ' tcx > > , tcx : TyCtxt < ' tcx > ) -> Self {
610+ tcx. mk_predicate ( from. map_bound ( |clause| PredicateKind :: Clause ( clause) ) ) . expect_clause ( )
610611 }
611612}
612613
613- impl < ' tcx > Upcast < ' tcx , TraitPredicate < ' tcx > > for TraitRef < ' tcx > {
614- #[ inline( always) ]
615- fn upcast ( self , _tcx : TyCtxt < ' tcx > ) -> TraitPredicate < ' tcx > {
616- TraitPredicate { trait_ref : self , polarity : PredicatePolarity :: Positive }
614+ impl < ' tcx > UpcastFrom < ' tcx , TraitRef < ' tcx > > for Predicate < ' tcx > {
615+ fn upcast_from ( from : TraitRef < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
616+ ty:: Binder :: dummy ( from) . upcast ( tcx)
617617 }
618618}
619619
620- impl < ' tcx > Upcast < ' tcx , Clause < ' tcx > > for TraitRef < ' tcx > {
621- #[ inline( always) ]
622- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Clause < ' tcx > {
623- let p: Predicate < ' tcx > = self . upcast ( tcx) ;
620+ impl < ' tcx > UpcastFrom < ' tcx , TraitRef < ' tcx > > for TraitPredicate < ' tcx > {
621+ fn upcast_from ( from : TraitRef < ' tcx > , _tcx : TyCtxt < ' tcx > ) -> Self {
622+ TraitPredicate { trait_ref : from, polarity : PredicatePolarity :: Positive }
623+ }
624+ }
625+
626+ impl < ' tcx > UpcastFrom < ' tcx , TraitRef < ' tcx > > for Clause < ' tcx > {
627+ fn upcast_from ( from : TraitRef < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
628+ let p: Predicate < ' tcx > = from. upcast ( tcx) ;
624629 p. expect_clause ( )
625630 }
626631}
627632
628- impl < ' tcx > Upcast < ' tcx , ty:: Predicate < ' tcx > > for Binder < ' tcx , TraitRef < ' tcx > > {
629- #[ inline( always) ]
630- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
631- let pred: PolyTraitPredicate < ' tcx > = self . upcast ( tcx) ;
633+ impl < ' tcx > UpcastFrom < ' tcx , Binder < ' tcx , TraitRef < ' tcx > > > for Predicate < ' tcx > {
634+ fn upcast_from ( from : Binder < ' tcx , TraitRef < ' tcx > > , tcx : TyCtxt < ' tcx > ) -> Self {
635+ let pred: PolyTraitPredicate < ' tcx > = from. upcast ( tcx) ;
632636 pred. upcast ( tcx)
633637 }
634638}
635639
636- impl < ' tcx > Upcast < ' tcx , Clause < ' tcx > > for Binder < ' tcx , TraitRef < ' tcx > > {
637- #[ inline( always) ]
638- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Clause < ' tcx > {
639- let pred: PolyTraitPredicate < ' tcx > = self . upcast ( tcx) ;
640+ impl < ' tcx > UpcastFrom < ' tcx , Binder < ' tcx , TraitRef < ' tcx > > > for Clause < ' tcx > {
641+ fn upcast_from ( from : Binder < ' tcx , TraitRef < ' tcx > > , tcx : TyCtxt < ' tcx > ) -> Self {
642+ let pred: PolyTraitPredicate < ' tcx > = from. upcast ( tcx) ;
640643 pred. upcast ( tcx)
641644 }
642645}
643646
644- impl < ' tcx > Upcast < ' tcx , PolyTraitPredicate < ' tcx > > for Binder < ' tcx , TraitRef < ' tcx > > {
645- #[ inline( always) ]
646- fn upcast ( self , _: TyCtxt < ' tcx > ) -> PolyTraitPredicate < ' tcx > {
647- self . map_bound ( |trait_ref| TraitPredicate {
647+ impl < ' tcx > UpcastFrom < ' tcx , Binder < ' tcx , TraitRef < ' tcx > > > for PolyTraitPredicate < ' tcx > {
648+ fn upcast_from ( from : Binder < ' tcx , TraitRef < ' tcx > > , _tcx : TyCtxt < ' tcx > ) -> Self {
649+ from. map_bound ( |trait_ref| TraitPredicate {
648650 trait_ref,
649- polarity : ty :: PredicatePolarity :: Positive ,
651+ polarity : PredicatePolarity :: Positive ,
650652 } )
651653 }
652654}
653655
654- impl < ' tcx > Upcast < ' tcx , ty :: Predicate < ' tcx > > for TraitPredicate < ' tcx > {
655- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
656- PredicateKind :: Clause ( ClauseKind :: Trait ( self ) ) . upcast ( tcx)
656+ impl < ' tcx > UpcastFrom < ' tcx , TraitPredicate < ' tcx > > for Predicate < ' tcx > {
657+ fn upcast_from ( from : TraitPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
658+ PredicateKind :: Clause ( ClauseKind :: Trait ( from ) ) . upcast ( tcx)
657659 }
658660}
659661
660- impl < ' tcx > Upcast < ' tcx , ty :: Predicate < ' tcx > > for PolyTraitPredicate < ' tcx > {
661- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
662- self . map_bound ( |p| PredicateKind :: Clause ( ClauseKind :: Trait ( p) ) ) . upcast ( tcx)
662+ impl < ' tcx > UpcastFrom < ' tcx , PolyTraitPredicate < ' tcx > > for Predicate < ' tcx > {
663+ fn upcast_from ( from : PolyTraitPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
664+ from . map_bound ( |p| PredicateKind :: Clause ( ClauseKind :: Trait ( p) ) ) . upcast ( tcx)
663665 }
664666}
665667
666- impl < ' tcx > Upcast < ' tcx , Clause < ' tcx > > for TraitPredicate < ' tcx > {
667- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Clause < ' tcx > {
668- let p: Predicate < ' tcx > = self . upcast ( tcx) ;
668+ impl < ' tcx > UpcastFrom < ' tcx , TraitPredicate < ' tcx > > for Clause < ' tcx > {
669+ fn upcast_from ( from : TraitPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
670+ let p: Predicate < ' tcx > = from . upcast ( tcx) ;
669671 p. expect_clause ( )
670672 }
671673}
672674
673- impl < ' tcx > Upcast < ' tcx , Clause < ' tcx > > for PolyTraitPredicate < ' tcx > {
674- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Clause < ' tcx > {
675- let p: Predicate < ' tcx > = self . upcast ( tcx) ;
675+ impl < ' tcx > UpcastFrom < ' tcx , PolyTraitPredicate < ' tcx > > for Clause < ' tcx > {
676+ fn upcast_from ( from : PolyTraitPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
677+ let p: Predicate < ' tcx > = from . upcast ( tcx) ;
676678 p. expect_clause ( )
677679 }
678680}
679681
680- impl < ' tcx > Upcast < ' tcx , ty :: Predicate < ' tcx > > for PolyRegionOutlivesPredicate < ' tcx > {
681- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
682- self . map_bound ( |p| PredicateKind :: Clause ( ClauseKind :: RegionOutlives ( p) ) ) . upcast ( tcx)
682+ impl < ' tcx > UpcastFrom < ' tcx , PolyRegionOutlivesPredicate < ' tcx > > for Predicate < ' tcx > {
683+ fn upcast_from ( from : PolyRegionOutlivesPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
684+ from . map_bound ( |p| PredicateKind :: Clause ( ClauseKind :: RegionOutlives ( p) ) ) . upcast ( tcx)
683685 }
684686}
685687
686- impl < ' tcx > Upcast < ' tcx , ty :: Predicate < ' tcx > > for OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > {
687- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
688- ty:: Binder :: dummy ( PredicateKind :: Clause ( ClauseKind :: TypeOutlives ( self ) ) ) . upcast ( tcx)
688+ impl < ' tcx > UpcastFrom < ' tcx , OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > for Predicate < ' tcx > {
689+ fn upcast_from ( from : OutlivesPredicate < Ty < ' tcx > , ty :: Region < ' tcx > > , tcx : TyCtxt < ' tcx > ) -> Self {
690+ ty:: Binder :: dummy ( PredicateKind :: Clause ( ClauseKind :: TypeOutlives ( from ) ) ) . upcast ( tcx)
689691 }
690692}
691693
692- impl < ' tcx > Upcast < ' tcx , ty :: Predicate < ' tcx > > for ProjectionPredicate < ' tcx > {
693- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
694- ty:: Binder :: dummy ( PredicateKind :: Clause ( ClauseKind :: Projection ( self ) ) ) . upcast ( tcx)
694+ impl < ' tcx > UpcastFrom < ' tcx , ProjectionPredicate < ' tcx > > for Predicate < ' tcx > {
695+ fn upcast_from ( from : ProjectionPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
696+ ty:: Binder :: dummy ( PredicateKind :: Clause ( ClauseKind :: Projection ( from ) ) ) . upcast ( tcx)
695697 }
696698}
697699
698- impl < ' tcx > Upcast < ' tcx , ty :: Predicate < ' tcx > > for PolyProjectionPredicate < ' tcx > {
699- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
700- self . map_bound ( |p| PredicateKind :: Clause ( ClauseKind :: Projection ( p) ) ) . upcast ( tcx)
700+ impl < ' tcx > UpcastFrom < ' tcx , PolyProjectionPredicate < ' tcx > > for Predicate < ' tcx > {
701+ fn upcast_from ( from : PolyProjectionPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
702+ from . map_bound ( |p| PredicateKind :: Clause ( ClauseKind :: Projection ( p) ) ) . upcast ( tcx)
701703 }
702704}
703705
704- impl < ' tcx > Upcast < ' tcx , Clause < ' tcx > > for ProjectionPredicate < ' tcx > {
705- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Clause < ' tcx > {
706- let p: Predicate < ' tcx > = self . upcast ( tcx) ;
706+ impl < ' tcx > UpcastFrom < ' tcx , ProjectionPredicate < ' tcx > > for Clause < ' tcx > {
707+ fn upcast_from ( from : ProjectionPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
708+ let p: Predicate < ' tcx > = from . upcast ( tcx) ;
707709 p. expect_clause ( )
708710 }
709711}
710712
711- impl < ' tcx > Upcast < ' tcx , Clause < ' tcx > > for PolyProjectionPredicate < ' tcx > {
712- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Clause < ' tcx > {
713- let p: Predicate < ' tcx > = self . upcast ( tcx) ;
713+ impl < ' tcx > UpcastFrom < ' tcx , PolyProjectionPredicate < ' tcx > > for Clause < ' tcx > {
714+ fn upcast_from ( from : PolyProjectionPredicate < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
715+ let p: Predicate < ' tcx > = from . upcast ( tcx) ;
714716 p. expect_clause ( )
715717 }
716718}
717719
718- impl < ' tcx > Upcast < ' tcx , ty :: Predicate < ' tcx > > for NormalizesTo < ' tcx > {
719- fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
720- PredicateKind :: NormalizesTo ( self ) . upcast ( tcx)
720+ impl < ' tcx > UpcastFrom < ' tcx , NormalizesTo < ' tcx > > for Predicate < ' tcx > {
721+ fn upcast_from ( from : NormalizesTo < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Self {
722+ PredicateKind :: NormalizesTo ( from ) . upcast ( tcx)
721723 }
722724}
723725
0 commit comments