@@ -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
@@ -193,32 +193,43 @@ impl TypeFoldable<'tcx> for hir::Constness {
193
193
/// identity fold, it should invoke `foo.fold_with(self)` to fold each
194
194
/// sub-item.
195
195
pub trait TypeFolder < ' tcx > : Sized {
196
+ type Error = !;
197
+
196
198
fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > ;
197
199
198
- fn fold_binder < T > ( & mut self , t : Binder < ' tcx , T > ) -> Binder < ' tcx , T >
200
+ fn fold_binder < T > ( & mut self , t : Binder < ' tcx , T > ) -> Result < Binder < ' tcx , T > , Self :: Error >
199
201
where
200
202
T : TypeFoldable < ' tcx > ,
201
203
{
202
204
t. super_fold_with ( self )
203
205
}
204
206
205
- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
207
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Self :: Error > {
206
208
t. super_fold_with ( self )
207
209
}
208
210
209
- fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
211
+ fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> Result < ty:: Region < ' tcx > , Self :: Error > {
210
212
r. super_fold_with ( self )
211
213
}
212
214
213
- fn fold_const ( & mut self , c : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
215
+ fn fold_const (
216
+ & mut self ,
217
+ c : & ' tcx ty:: Const < ' tcx > ,
218
+ ) -> Result < & ' tcx ty:: Const < ' tcx > , Self :: Error > {
214
219
c. super_fold_with ( self )
215
220
}
216
221
217
- fn fold_predicate ( & mut self , p : ty:: Predicate < ' tcx > ) -> ty:: Predicate < ' tcx > {
222
+ fn fold_predicate (
223
+ & mut self ,
224
+ p : ty:: Predicate < ' tcx > ,
225
+ ) -> Result < ty:: Predicate < ' tcx > , Self :: Error > {
218
226
p. super_fold_with ( self )
219
227
}
220
228
221
- fn fold_mir_const ( & mut self , c : mir:: ConstantKind < ' tcx > ) -> mir:: ConstantKind < ' tcx > {
229
+ fn fold_mir_const (
230
+ & mut self ,
231
+ c : mir:: ConstantKind < ' tcx > ,
232
+ ) -> Result < mir:: ConstantKind < ' tcx > , Self :: Error > {
222
233
bug ! ( "most type folders should not be folding MIR datastructures: {:?}" , c)
223
234
}
224
235
}
0 commit comments