@@ -17,7 +17,7 @@ use smallvec::SmallVec;
17
17
use crate :: ty:: codec:: { TyDecoder , TyEncoder } ;
18
18
use crate :: ty:: {
19
19
self , ClosureArgs , CoroutineArgs , CoroutineClosureArgs , FallibleTypeFolder , InlineConstArgs ,
20
- Lift , List , Ty , TyCtxt , TypeFoldable , TypeVisitable , TypeVisitor , VisitorResult ,
20
+ Lift , List , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeVisitable , TypeVisitor , VisitorResult ,
21
21
walk_visitable_list,
22
22
} ;
23
23
@@ -337,6 +337,14 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArg<'tcx> {
337
337
GenericArgKind :: Const ( ct) => ct. try_fold_with ( folder) . map ( Into :: into) ,
338
338
}
339
339
}
340
+
341
+ fn fold_with < F : TypeFolder < TyCtxt < ' tcx > > > ( self , folder : & mut F ) -> Self {
342
+ match self . unpack ( ) {
343
+ GenericArgKind :: Lifetime ( lt) => lt. fold_with ( folder) . into ( ) ,
344
+ GenericArgKind :: Type ( ty) => ty. fold_with ( folder) . into ( ) ,
345
+ GenericArgKind :: Const ( ct) => ct. fold_with ( folder) . into ( ) ,
346
+ }
347
+ }
340
348
}
341
349
342
350
impl < ' tcx > TypeVisitable < TyCtxt < ' tcx > > for GenericArg < ' tcx > {
@@ -606,6 +614,27 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArgsRef<'tcx> {
606
614
}
607
615
}
608
616
0 => Ok ( self ) ,
617
+ _ => ty:: util:: try_fold_list ( self , folder, |tcx, v| tcx. mk_args ( v) ) ,
618
+ }
619
+ }
620
+
621
+ fn fold_with < F : TypeFolder < TyCtxt < ' tcx > > > ( self , folder : & mut F ) -> Self {
622
+ // See justification for this behavior in `try_fold_with`.
623
+ match self . len ( ) {
624
+ 1 => {
625
+ let param0 = self [ 0 ] . fold_with ( folder) ;
626
+ if param0 == self [ 0 ] { self } else { folder. cx ( ) . mk_args ( & [ param0] ) }
627
+ }
628
+ 2 => {
629
+ let param0 = self [ 0 ] . fold_with ( folder) ;
630
+ let param1 = self [ 1 ] . fold_with ( folder) ;
631
+ if param0 == self [ 0 ] && param1 == self [ 1 ] {
632
+ self
633
+ } else {
634
+ folder. cx ( ) . mk_args ( & [ param0, param1] )
635
+ }
636
+ }
637
+ 0 => self ,
609
638
_ => ty:: util:: fold_list ( self , folder, |tcx, v| tcx. mk_args ( v) ) ,
610
639
}
611
640
}
@@ -641,6 +670,22 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
641
670
Ok ( folder. cx ( ) . mk_type_list ( & [ param0, param1] ) )
642
671
}
643
672
}
673
+ _ => ty:: util:: try_fold_list ( self , folder, |tcx, v| tcx. mk_type_list ( v) ) ,
674
+ }
675
+ }
676
+
677
+ fn fold_with < F : TypeFolder < TyCtxt < ' tcx > > > ( self , folder : & mut F ) -> Self {
678
+ // See comment justifying behavior in `try_fold_with`.
679
+ match self . len ( ) {
680
+ 2 => {
681
+ let param0 = self [ 0 ] . fold_with ( folder) ;
682
+ let param1 = self [ 1 ] . fold_with ( folder) ;
683
+ if param0 == self [ 0 ] && param1 == self [ 1 ] {
684
+ self
685
+ } else {
686
+ folder. cx ( ) . mk_type_list ( & [ param0, param1] )
687
+ }
688
+ }
644
689
_ => ty:: util:: fold_list ( self , folder, |tcx, v| tcx. mk_type_list ( v) ) ,
645
690
}
646
691
}
0 commit comments