@@ -816,11 +816,14 @@ impl<'tcx> List<ty::PolyExistentialPredicate<'tcx>> {
816
816
pub struct TraitRef < ' tcx > {
817
817
pub def_id : DefId ,
818
818
pub substs : SubstsRef < ' tcx > ,
819
+ /// This field exists to prevent the creation of `TraitRef` without
820
+ /// calling [TyCtxt::mk_trait_ref].
821
+ _use_mk_trait_ref_instead : ( ) ,
819
822
}
820
823
821
824
impl < ' tcx > TraitRef < ' tcx > {
822
825
pub fn new ( def_id : DefId , substs : SubstsRef < ' tcx > ) -> TraitRef < ' tcx > {
823
- TraitRef { def_id, substs }
826
+ TraitRef { def_id, substs, _use_mk_trait_ref_instead : ( ) }
824
827
}
825
828
826
829
pub fn with_self_ty ( self , tcx : TyCtxt < ' tcx > , self_ty : Ty < ' tcx > ) -> Self {
@@ -836,6 +839,7 @@ impl<'tcx> TraitRef<'tcx> {
836
839
ty:: Binder :: dummy ( TraitRef {
837
840
def_id,
838
841
substs : InternalSubsts :: identity_for_item ( tcx, def_id) ,
842
+ _use_mk_trait_ref_instead : ( ) ,
839
843
} )
840
844
}
841
845
@@ -850,7 +854,11 @@ impl<'tcx> TraitRef<'tcx> {
850
854
substs : SubstsRef < ' tcx > ,
851
855
) -> ty:: TraitRef < ' tcx > {
852
856
let defs = tcx. generics_of ( trait_id) ;
853
- ty:: TraitRef { def_id : trait_id, substs : tcx. intern_substs ( & substs[ ..defs. params . len ( ) ] ) }
857
+ ty:: TraitRef {
858
+ def_id : trait_id,
859
+ substs : tcx. intern_substs ( & substs[ ..defs. params . len ( ) ] ) ,
860
+ _use_mk_trait_ref_instead : ( ) ,
861
+ }
854
862
}
855
863
}
856
864
@@ -1194,10 +1202,7 @@ impl<'tcx> AliasTy<'tcx> {
1194
1202
let trait_def_id = self . trait_def_id ( tcx) ;
1195
1203
let trait_generics = tcx. generics_of ( trait_def_id) ;
1196
1204
(
1197
- ty:: TraitRef {
1198
- def_id : trait_def_id,
1199
- substs : self . substs . truncate_to ( tcx, trait_generics) ,
1200
- } ,
1205
+ tcx. mk_trait_ref ( trait_def_id, self . substs . truncate_to ( tcx, trait_generics) ) ,
1201
1206
& self . substs [ trait_generics. count ( ) ..] ,
1202
1207
)
1203
1208
}
@@ -1211,7 +1216,7 @@ impl<'tcx> AliasTy<'tcx> {
1211
1216
/// as well.
1212
1217
pub fn trait_ref ( & self , tcx : TyCtxt < ' tcx > ) -> ty:: TraitRef < ' tcx > {
1213
1218
let def_id = self . trait_def_id ( tcx) ;
1214
- ty :: TraitRef { def_id, substs : self . substs . truncate_to ( tcx, tcx. generics_of ( def_id) ) }
1219
+ tcx . mk_trait_ref ( def_id, self . substs . truncate_to ( tcx, tcx. generics_of ( def_id) ) )
1215
1220
}
1216
1221
1217
1222
pub fn self_ty ( & self ) -> Ty < ' tcx > {
0 commit comments