11use std:: ops:: ControlFlow ;
22
3- use crate :: Opaque ;
3+ use crate :: {
4+ ty:: { self , BoundRegion , BoundRegionKind } ,
5+ Opaque ,
6+ } ;
47
58use super :: ty:: {
69 Allocation , Binder , Const , ConstDef , ConstantKind , ExistentialPredicate , FnSig , GenericArgKind ,
@@ -15,6 +18,9 @@ pub trait Folder: Sized {
1518 fn fold_const ( & mut self , c : & Const ) -> ControlFlow < Self :: Break , Const > {
1619 c. super_fold ( self )
1720 }
21+ fn visit_reg ( & mut self , reg : & Region ) -> ControlFlow < Self :: Break , Region > {
22+ reg. super_fold ( self )
23+ }
1824}
1925
2026pub trait Foldable : Sized + Clone {
@@ -107,8 +113,39 @@ impl Foldable for GenericArgs {
107113}
108114
109115impl Foldable for Region {
116+ fn fold < V : Folder > ( & self , folder : & mut V ) -> ControlFlow < V :: Break , Self > {
117+ folder. visit_reg ( self )
118+ }
119+ fn super_fold < V : Folder > ( & self , folder : & mut V ) -> ControlFlow < V :: Break , Self > {
120+ let mut kind = self . kind . clone ( ) ;
121+ match & mut kind {
122+ crate :: ty:: RegionKind :: ReEarlyBound ( _) => { }
123+ crate :: ty:: RegionKind :: ReLateBound ( _, bound_reg) => {
124+ * bound_reg = bound_reg. fold ( folder) ?
125+ }
126+ crate :: ty:: RegionKind :: ReStatic => { }
127+ crate :: ty:: RegionKind :: RePlaceholder ( bound_reg) => {
128+ bound_reg. bound = bound_reg. bound . fold ( folder) ?
129+ }
130+ crate :: ty:: RegionKind :: ReErased => { }
131+ }
132+ ControlFlow :: Continue ( ty:: Region { kind : kind } . into ( ) )
133+ }
134+ }
135+
136+ impl Foldable for BoundRegion {
137+ fn super_fold < V : Folder > ( & self , folder : & mut V ) -> ControlFlow < V :: Break , Self > {
138+ ControlFlow :: Continue ( BoundRegion { var : self . var , kind : self . kind . fold ( folder) ? } )
139+ }
140+ }
141+
142+ impl Foldable for BoundRegionKind {
110143 fn super_fold < V : Folder > ( & self , _folder : & mut V ) -> ControlFlow < V :: Break , Self > {
111- ControlFlow :: Continue ( self . clone ( ) )
144+ match self {
145+ BoundRegionKind :: BrAnon => ControlFlow :: Continue ( self . clone ( ) ) ,
146+ BoundRegionKind :: BrNamed ( _, _) => ControlFlow :: Continue ( self . clone ( ) ) ,
147+ BoundRegionKind :: BrEnv => ControlFlow :: Continue ( self . clone ( ) ) ,
148+ }
112149 }
113150}
114151
0 commit comments