@@ -46,8 +46,8 @@ use std::ops::ControlFlow;
46
46
///
47
47
/// To implement this conveniently, use the derive macro located in `rustc_macros`.
48
48
pub trait TypeFoldable < ' tcx > : fmt:: Debug + Clone {
49
- fn super_fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self ;
50
- fn fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
49
+ fn super_fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Result < Self , F :: Error > ;
50
+ fn fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Result < Self , F :: Error > {
51
51
self . super_fold_with ( folder)
52
52
}
53
53
@@ -161,28 +161,36 @@ impl TypeFoldable<'tcx> for hir::Constness {
161
161
/// identity fold, it should invoke `foo.fold_with(self)` to fold each
162
162
/// sub-item.
163
163
pub trait TypeFolder < ' tcx > : Sized {
164
+ type Error = !;
165
+
164
166
fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > ;
165
167
166
- fn fold_binder < T > ( & mut self , t : Binder < ' tcx , T > ) -> Binder < ' tcx , T >
168
+ fn fold_binder < T > ( & mut self , t : Binder < ' tcx , T > ) -> Result < Binder < ' tcx , T > , Self :: Error >
167
169
where
168
170
T : TypeFoldable < ' tcx > ,
169
171
{
170
172
t. super_fold_with ( self )
171
173
}
172
174
173
- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
175
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Self :: Error > {
174
176
t. super_fold_with ( self )
175
177
}
176
178
177
- fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
179
+ fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> Result < ty:: Region < ' tcx > , Self :: Error > {
178
180
r. super_fold_with ( self )
179
181
}
180
182
181
- fn fold_const ( & mut self , c : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
183
+ fn fold_const (
184
+ & mut self ,
185
+ c : & ' tcx ty:: Const < ' tcx > ,
186
+ ) -> Result < & ' tcx ty:: Const < ' tcx > , Self :: Error > {
182
187
c. super_fold_with ( self )
183
188
}
184
189
185
- fn fold_mir_const ( & mut self , c : mir:: ConstantKind < ' tcx > ) -> mir:: ConstantKind < ' tcx > {
190
+ fn fold_mir_const (
191
+ & mut self ,
192
+ c : mir:: ConstantKind < ' tcx > ,
193
+ ) -> Result < mir:: ConstantKind < ' tcx > , Self :: Error > {
186
194
bug ! ( "most type folders should not be folding MIR datastructures: {:?}" , c)
187
195
}
188
196
}
0 commit comments