@@ -13,7 +13,6 @@ use rustc_hir::def::Namespace;
13
13
use rustc_hir:: def_id:: CRATE_DEF_INDEX ;
14
14
use rustc_index:: vec:: { Idx , IndexVec } ;
15
15
16
- use smallvec:: SmallVec ;
17
16
use std:: fmt;
18
17
use std:: ops:: ControlFlow ;
19
18
use std:: rc:: Rc ;
@@ -275,7 +274,7 @@ impl fmt::Debug for ty::PredicateAtom<'tcx> {
275
274
// For things that don't carry any arena-allocated data (and are
276
275
// copy...), just add them to this list.
277
276
278
- CloneTypeFoldableAndLiftImpls ! {
277
+ TrivialTypeFoldableAndLiftImpls ! {
279
278
( ) ,
280
279
bool ,
281
280
usize ,
@@ -846,7 +845,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
846
845
847
846
impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx ty:: List < ty:: ExistentialPredicate < ' tcx > > {
848
847
fn super_fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
849
- fold_list ( self , folder, |tcx, v| tcx. intern_existential_predicates ( v) )
848
+ ty :: util :: fold_list ( self , folder, |tcx, v| tcx. intern_existential_predicates ( v) )
850
849
}
851
850
852
851
fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> ControlFlow < ( ) > {
@@ -856,7 +855,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>>
856
855
857
856
impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx ty:: List < Ty < ' tcx > > {
858
857
fn super_fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
859
- fold_list ( self , folder, |tcx, v| tcx. intern_type_list ( v) )
858
+ ty :: util :: fold_list ( self , folder, |tcx, v| tcx. intern_type_list ( v) )
860
859
}
861
860
862
861
fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> ControlFlow < ( ) > {
@@ -866,7 +865,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
866
865
867
866
impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx ty:: List < ProjectionKind > {
868
867
fn super_fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
869
- fold_list ( self , folder, |tcx, v| tcx. intern_projs ( v) )
868
+ ty :: util :: fold_list ( self , folder, |tcx, v| tcx. intern_projs ( v) )
870
869
}
871
870
872
871
fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> ControlFlow < ( ) > {
@@ -928,25 +927,25 @@ impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
928
927
929
928
impl < ' tcx > TypeFoldable < ' tcx > for Ty < ' tcx > {
930
929
fn super_fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
931
- let kind = match self . kind ( ) {
930
+ let kind = match * self . kind ( ) {
932
931
ty:: RawPtr ( tm) => ty:: RawPtr ( tm. fold_with ( folder) ) ,
933
932
ty:: Array ( typ, sz) => ty:: Array ( typ. fold_with ( folder) , sz. fold_with ( folder) ) ,
934
933
ty:: Slice ( typ) => ty:: Slice ( typ. fold_with ( folder) ) ,
935
- ty:: Adt ( tid, substs) => ty:: Adt ( * tid, substs. fold_with ( folder) ) ,
936
- ty:: Dynamic ( ref trait_ty, ref region) => {
934
+ ty:: Adt ( tid, substs) => ty:: Adt ( tid, substs. fold_with ( folder) ) ,
935
+ ty:: Dynamic ( trait_ty, region) => {
937
936
ty:: Dynamic ( trait_ty. fold_with ( folder) , region. fold_with ( folder) )
938
937
}
939
938
ty:: Tuple ( ts) => ty:: Tuple ( ts. fold_with ( folder) ) ,
940
- ty:: FnDef ( def_id, substs) => ty:: FnDef ( * def_id, substs. fold_with ( folder) ) ,
939
+ ty:: FnDef ( def_id, substs) => ty:: FnDef ( def_id, substs. fold_with ( folder) ) ,
941
940
ty:: FnPtr ( f) => ty:: FnPtr ( f. fold_with ( folder) ) ,
942
- ty:: Ref ( ref r, ty, mutbl) => ty:: Ref ( r. fold_with ( folder) , ty. fold_with ( folder) , * mutbl) ,
941
+ ty:: Ref ( r, ty, mutbl) => ty:: Ref ( r. fold_with ( folder) , ty. fold_with ( folder) , mutbl) ,
943
942
ty:: Generator ( did, substs, movability) => {
944
- ty:: Generator ( * did, substs. fold_with ( folder) , * movability)
943
+ ty:: Generator ( did, substs. fold_with ( folder) , movability)
945
944
}
946
945
ty:: GeneratorWitness ( types) => ty:: GeneratorWitness ( types. fold_with ( folder) ) ,
947
- ty:: Closure ( did, substs) => ty:: Closure ( * did, substs. fold_with ( folder) ) ,
948
- ty:: Projection ( ref data) => ty:: Projection ( data. fold_with ( folder) ) ,
949
- ty:: Opaque ( did, substs) => ty:: Opaque ( * did, substs. fold_with ( folder) ) ,
946
+ ty:: Closure ( did, substs) => ty:: Closure ( did, substs. fold_with ( folder) ) ,
947
+ ty:: Projection ( data) => ty:: Projection ( data. fold_with ( folder) ) ,
948
+ ty:: Opaque ( did, substs) => ty:: Opaque ( did, substs. fold_with ( folder) ) ,
950
949
951
950
ty:: Bool
952
951
| ty:: Char
@@ -1060,7 +1059,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
1060
1059
1061
1060
impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx ty:: List < ty:: Predicate < ' tcx > > {
1062
1061
fn super_fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
1063
- fold_list ( self , folder, |tcx, v| tcx. intern_predicates ( v) )
1062
+ ty :: util :: fold_list ( self , folder, |tcx, v| tcx. intern_predicates ( v) )
1064
1063
}
1065
1064
1066
1065
fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> ControlFlow < ( ) > {
@@ -1140,34 +1139,3 @@ impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
1140
1139
ControlFlow :: CONTINUE
1141
1140
}
1142
1141
}
1143
-
1144
- // Does the equivalent of
1145
- // ```
1146
- // let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
1147
- // folder.tcx().intern_*(&v)
1148
- // ```
1149
- fn fold_list < ' tcx , F , T > (
1150
- list : & ' tcx ty:: List < T > ,
1151
- folder : & mut F ,
1152
- intern : impl FnOnce ( TyCtxt < ' tcx > , & [ T ] ) -> & ' tcx ty:: List < T > ,
1153
- ) -> & ' tcx ty:: List < T >
1154
- where
1155
- F : TypeFolder < ' tcx > ,
1156
- T : TypeFoldable < ' tcx > + PartialEq + Copy ,
1157
- {
1158
- let mut iter = list. iter ( ) ;
1159
- // Look for the first element that changed
1160
- if let Some ( ( i, new_t) ) = iter. by_ref ( ) . enumerate ( ) . find_map ( |( i, t) | {
1161
- let new_t = t. fold_with ( folder) ;
1162
- if new_t == t { None } else { Some ( ( i, new_t) ) }
1163
- } ) {
1164
- // An element changed, prepare to intern the resulting list
1165
- let mut new_list = SmallVec :: < [ _ ; 8 ] > :: with_capacity ( list. len ( ) ) ;
1166
- new_list. extend_from_slice ( & list[ ..i] ) ;
1167
- new_list. push ( new_t) ;
1168
- new_list. extend ( iter. map ( |t| t. fold_with ( folder) ) ) ;
1169
- intern ( folder. tcx ( ) , & new_list)
1170
- } else {
1171
- list
1172
- }
1173
- }
0 commit comments