1
1
use std:: ops:: ControlFlow ;
2
2
3
- use crate :: Opaque ;
3
+ use crate :: {
4
+ ty:: { self , BoundRegion , BoundRegionKind } ,
5
+ Opaque ,
6
+ } ;
4
7
5
8
use super :: ty:: {
6
9
Allocation , Binder , Const , ConstDef , ConstantKind , ExistentialPredicate , FnSig , GenericArgKind ,
@@ -15,6 +18,9 @@ pub trait Folder: Sized {
15
18
fn fold_const ( & mut self , c : & Const ) -> ControlFlow < Self :: Break , Const > {
16
19
c. super_fold ( self )
17
20
}
21
+ fn visit_reg ( & mut self , reg : & Region ) -> ControlFlow < Self :: Break , Region > {
22
+ reg. super_fold ( self )
23
+ }
18
24
}
19
25
20
26
pub trait Foldable : Sized + Clone {
@@ -107,8 +113,39 @@ impl Foldable for GenericArgs {
107
113
}
108
114
109
115
impl 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 {
110
143
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
+ }
112
149
}
113
150
}
114
151
0 commit comments