@@ -4,17 +4,20 @@ use crate::Opaque;
44
55use super :: ty:: {
66 Allocation , Binder , Const , ConstDef , ConstantKind , ExistentialPredicate , FnSig , GenericArgKind ,
7- GenericArgs , Promoted , RigidTy , TermKind , Ty , TyKind , UnevaluatedConst ,
7+ GenericArgs , Promoted , Region , RigidTy , TermKind , Ty , TyKind , UnevaluatedConst ,
88} ;
99
1010pub trait Folder : Sized {
1111 type Break ;
12- fn visit_ty ( & mut self , ty : & Ty ) -> ControlFlow < Self :: Break , Ty > {
12+ fn fold_ty ( & mut self , ty : & Ty ) -> ControlFlow < Self :: Break , Ty > {
1313 ty. super_fold ( self )
1414 }
1515 fn fold_const ( & mut self , c : & Const ) -> ControlFlow < Self :: Break , Const > {
1616 c. super_fold ( self )
1717 }
18+ fn fold_reg ( & mut self , reg : & Region ) -> ControlFlow < Self :: Break , Region > {
19+ reg. super_fold ( self )
20+ }
1821}
1922
2023pub trait Foldable : Sized + Clone {
@@ -26,7 +29,7 @@ pub trait Foldable: Sized + Clone {
2629
2730impl Foldable for Ty {
2831 fn fold < V : Folder > ( & self , folder : & mut V ) -> ControlFlow < V :: Break , Self > {
29- folder. visit_ty ( self )
32+ folder. fold_ty ( self )
3033 }
3134 fn super_fold < V : Folder > ( & self , folder : & mut V ) -> ControlFlow < V :: Break , Self > {
3235 let mut kind = self . kind ( ) ;
@@ -106,6 +109,15 @@ impl Foldable for GenericArgs {
106109 }
107110}
108111
112+ impl Foldable for Region {
113+ fn fold < V : Folder > ( & self , folder : & mut V ) -> ControlFlow < V :: Break , Self > {
114+ folder. fold_reg ( self )
115+ }
116+ fn super_fold < V : Folder > ( & self , _: & mut V ) -> ControlFlow < V :: Break , Self > {
117+ ControlFlow :: Continue ( self . clone ( ) )
118+ }
119+ }
120+
109121impl Foldable for GenericArgKind {
110122 fn super_fold < V : Folder > ( & self , folder : & mut V ) -> ControlFlow < V :: Break , Self > {
111123 let mut this = self . clone ( ) ;
@@ -136,7 +148,10 @@ impl Foldable for RigidTy {
136148 }
137149 RigidTy :: Slice ( inner) => * inner = inner. fold ( folder) ?,
138150 RigidTy :: RawPtr ( ty, _) => * ty = ty. fold ( folder) ?,
139- RigidTy :: Ref ( _, ty, _) => * ty = ty. fold ( folder) ?,
151+ RigidTy :: Ref ( reg, ty, _) => {
152+ * reg = reg. fold ( folder) ?;
153+ * ty = ty. fold ( folder) ?
154+ }
140155 RigidTy :: FnDef ( _, args) => * args = args. fold ( folder) ?,
141156 RigidTy :: FnPtr ( sig) => * sig = sig. fold ( folder) ?,
142157 RigidTy :: Closure ( _, args) => * args = args. fold ( folder) ?,
@@ -214,7 +229,7 @@ pub enum Never {}
214229impl Folder for GenericArgs {
215230 type Break = Never ;
216231
217- fn visit_ty ( & mut self , ty : & Ty ) -> ControlFlow < Self :: Break , Ty > {
232+ fn fold_ty ( & mut self , ty : & Ty ) -> ControlFlow < Self :: Break , Ty > {
218233 ControlFlow :: Continue ( match ty. kind ( ) {
219234 TyKind :: Param ( p) => self [ p] ,
220235 _ => * ty,
0 commit comments