@@ -622,6 +622,18 @@ impl<'tcx> TraitRef<'tcx> {
622
622
// associated types.
623
623
self . substs . types ( )
624
624
}
625
+
626
+ pub fn from_method ( tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
627
+ trait_id : DefId ,
628
+ substs : & Substs < ' tcx > )
629
+ -> ty:: TraitRef < ' tcx > {
630
+ let defs = tcx. generics_of ( trait_id) ;
631
+
632
+ ty:: TraitRef {
633
+ def_id : trait_id,
634
+ substs : tcx. intern_substs ( & substs[ ..defs. params . len ( ) ] )
635
+ }
636
+ }
625
637
}
626
638
627
639
pub type PolyTraitRef < ' tcx > = Binder < TraitRef < ' tcx > > ;
@@ -663,6 +675,18 @@ impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> {
663
675
self . substs . types ( )
664
676
}
665
677
678
+ pub fn erase_self_ty ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
679
+ trait_ref : ty:: TraitRef < ' tcx > )
680
+ -> ty:: ExistentialTraitRef < ' tcx > {
681
+ // Assert there is a Self.
682
+ trait_ref. substs . type_at ( 0 ) ;
683
+
684
+ ty:: ExistentialTraitRef {
685
+ def_id : trait_ref. def_id ,
686
+ substs : tcx. intern_substs ( & trait_ref. substs [ 1 ..] )
687
+ }
688
+ }
689
+
666
690
/// Object types don't have a self-type specified. Therefore, when
667
691
/// we convert the principal trait-ref into a normal trait-ref,
668
692
/// you must give *some* self-type. A common choice is `mk_err()`
@@ -674,8 +698,7 @@ impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> {
674
698
675
699
ty:: TraitRef {
676
700
def_id : self . def_id ,
677
- substs : tcx. mk_substs (
678
- iter:: once ( self_ty. into ( ) ) . chain ( self . substs . iter ( ) . cloned ( ) ) )
701
+ substs : tcx. mk_substs_trait ( self_ty, self . substs )
679
702
}
680
703
}
681
704
}
@@ -686,6 +709,16 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
686
709
pub fn def_id ( & self ) -> DefId {
687
710
self . skip_binder ( ) . def_id
688
711
}
712
+
713
+ /// Object types don't have a self-type specified. Therefore, when
714
+ /// we convert the principal trait-ref into a normal trait-ref,
715
+ /// you must give *some* self-type. A common choice is `mk_err()`
716
+ /// or some skolemized type.
717
+ pub fn with_self_ty ( & self , tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
718
+ self_ty : Ty < ' tcx > )
719
+ -> ty:: PolyTraitRef < ' tcx > {
720
+ self . map_bound ( |trait_ref| trait_ref. with_self_ty ( tcx, self_ty) )
721
+ }
689
722
}
690
723
691
724
/// Binder is a binder for higher-ranked lifetimes. It is part of the
@@ -1188,8 +1221,7 @@ impl<'a, 'tcx, 'gcx> ExistentialProjection<'tcx> {
1188
1221
ty:: ProjectionPredicate {
1189
1222
projection_ty : ty:: ProjectionTy {
1190
1223
item_def_id : self . item_def_id ,
1191
- substs : tcx. mk_substs (
1192
- iter:: once ( self_ty. into ( ) ) . chain ( self . substs . iter ( ) . cloned ( ) ) ) ,
1224
+ substs : tcx. mk_substs_trait ( self_ty, self . substs ) ,
1193
1225
} ,
1194
1226
ty : self . ty ,
1195
1227
}
0 commit comments