@@ -856,11 +856,13 @@ impl CompressedTraitRefs {
856856 #[ inline]
857857 pub fn trait_clause_from_def_id < I : Interner > (
858858 cx : I ,
859- self_ty : I :: Ty ,
859+ self_ty : I :: GenericArgs ,
860860 def_id : I :: TraitId ,
861861 ) -> Binder < I , TraitClause < I > > {
862+ // Note that `self_ty` is a GenericArgs, but only contains a single
863+ // argument which is the trait's self_ty. This is done for perf.
862864 Binder :: dummy ( TraitClause {
863- trait_ref : TraitRef :: new ( cx, def_id, [ self_ty] ) ,
865+ trait_ref : TraitRef :: new_from_args ( cx, def_id, self_ty) ,
864866 polarity : ClausePolarity :: Positive ,
865867 } )
866868 }
@@ -869,7 +871,7 @@ impl CompressedTraitRefs {
869871 pub fn trait_clause_from_single_bit < I : Interner > (
870872 self ,
871873 cx : I ,
872- self_ty : I :: Ty ,
874+ self_ty : I :: GenericArgs ,
873875 ) -> Binder < I , TraitClause < I > > {
874876 Self :: trait_clause_from_def_id (
875877 cx,
@@ -899,7 +901,12 @@ impl CompressedTraitRefs {
899901 derive( Encodable_NoContext , Decodable_NoContext , StableHash_NoContext )
900902) ]
901903pub struct CompressedTraitClause < I : Interner > {
902- pub self_ty : I :: Ty ,
904+ // Note: always only contains a single self ty.
905+ // Storing it as `GenericArgs` makes decompression faster.
906+ // Note that some of the folds and visits we do over compressed traits
907+ // ignore the trait ref and only recurses into self_ty. This is *incorrect*
908+ // if `self_ty` ever contained more than one generic arg.
909+ pub self_ty : I :: GenericArgs ,
903910
904911 #[ type_foldable( identity) ]
905912 #[ type_visitable( ignore) ]
@@ -932,7 +939,10 @@ impl<I: Interner> CompressedTraitClause<I> {
932939 let compressed_trait_refs =
933940 CompressedTraitRefs :: from_lang_item ( cx. as_trait_lang_item ( trait_ref. def_id ) ?) ?;
934941
935- Some ( Self { self_ty : trait_ref. self_ty ( ) , compressed_trait_refs } )
942+ // The args of the trait ref should *only* contain a self ty
943+ // when used in a compressed clause.
944+ debug_assert_eq ! ( trait_ref. args. len( ) , 1 ) ;
945+ Some ( Self { self_ty : trait_ref. args , compressed_trait_refs } )
936946 }
937947 ClauseKind :: RegionOutlives ( _) => None ,
938948 ClauseKind :: TypeOutlives ( _) => None ,
0 commit comments