@@ -544,180 +544,182 @@ impl<'tcx> ToPolyTraitRef<'tcx> for PolyTraitPredicate<'tcx> {
544
544
}
545
545
}
546
546
547
+ /// An `Into`-like trait that takes `TyCtxt` to perform interner-specific transformations.
547
548
pub trait Upcast < ' tcx , T > {
548
549
fn upcast ( self , tcx : TyCtxt < ' tcx > ) -> T ;
549
550
}
550
551
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)
554
558
}
555
559
}
556
560
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
561
569
}
562
570
}
563
571
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)
568
575
}
569
576
}
570
577
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)
575
581
}
576
582
}
577
583
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) ) )
582
587
}
583
588
}
584
589
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 ) )
589
593
}
590
594
}
591
595
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 ( )
596
599
}
597
600
}
598
601
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 ( )
603
605
}
604
606
}
605
607
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 ( )
610
611
}
611
612
}
612
613
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)
617
617
}
618
618
}
619
619
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) ;
624
629
p. expect_clause ( )
625
630
}
626
631
}
627
632
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) ;
632
636
pred. upcast ( tcx)
633
637
}
634
638
}
635
639
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) ;
640
643
pred. upcast ( tcx)
641
644
}
642
645
}
643
646
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 {
648
650
trait_ref,
649
- polarity : ty :: PredicatePolarity :: Positive ,
651
+ polarity : PredicatePolarity :: Positive ,
650
652
} )
651
653
}
652
654
}
653
655
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)
657
659
}
658
660
}
659
661
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)
663
665
}
664
666
}
665
667
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) ;
669
671
p. expect_clause ( )
670
672
}
671
673
}
672
674
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) ;
676
678
p. expect_clause ( )
677
679
}
678
680
}
679
681
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)
683
685
}
684
686
}
685
687
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)
689
691
}
690
692
}
691
693
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)
695
697
}
696
698
}
697
699
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)
701
703
}
702
704
}
703
705
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) ;
707
709
p. expect_clause ( )
708
710
}
709
711
}
710
712
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) ;
714
716
p. expect_clause ( )
715
717
}
716
718
}
717
719
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)
721
723
}
722
724
}
723
725
0 commit comments