@@ -86,7 +86,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
86
86
/// A convenient alternative to `try_fold_with` for use with infallible
87
87
/// folders. Do not override this method, to ensure coherence with
88
88
/// `try_fold_with`.
89
- fn fold_with < F : TypeFolder < ' tcx , Error = ! > > ( self , folder : & mut F ) -> Self {
89
+ fn fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
90
90
self . try_fold_with ( folder) . into_ok ( )
91
91
}
92
92
@@ -216,7 +216,7 @@ pub trait TypeSuperFoldable<'tcx>: TypeFoldable<'tcx> {
216
216
/// A convenient alternative to `try_super_fold_with` for use with
217
217
/// infallible folders. Do not override this method, to ensure coherence
218
218
/// with `try_super_fold_with`.
219
- fn super_fold_with < F : TypeFolder < ' tcx , Error = ! > > ( self , folder : & mut F ) -> Self {
219
+ fn super_fold_with < F : TypeFolder < ' tcx > > ( self , folder : & mut F ) -> Self {
220
220
self . try_super_fold_with ( folder) . into_ok ( )
221
221
}
222
222
@@ -229,70 +229,46 @@ pub trait TypeSuperFoldable<'tcx>: TypeFoldable<'tcx> {
229
229
fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> ControlFlow < V :: BreakTy > ;
230
230
}
231
231
232
- /// This trait is implemented for every folding traversal. There is a fold
233
- /// method defined for every type of interest. Each such method has a default
234
- /// that does an "identity" fold. Implementations of these methods often fall
235
- /// back to a `super_fold_with` method if the primary argument doesn't
236
- /// satisfy a particular condition.
232
+ /// This trait is implemented for every infallible folding traversal. There is
233
+ /// a fold method defined for every type of interest. Each such method has a
234
+ /// default that does an "identity" fold. Implementations of these methods
235
+ /// often fall back to a `super_fold_with` method if the primary argument
236
+ /// doesn't satisfy a particular condition.
237
237
///
238
- /// If this folder is fallible (and therefore its [`Error`][`TypeFolder::Error`]
239
- /// associated type is something other than the default `!`) then
240
- /// [`FallibleTypeFolder`] should be implemented manually. Otherwise,
241
- /// a blanket implementation of [`FallibleTypeFolder`] will defer to
238
+ /// A blanket implementation of [`FallibleTypeFolder`] will defer to
242
239
/// the infallible methods of this trait to ensure that the two APIs
243
240
/// are coherent.
244
- pub trait TypeFolder < ' tcx > : Sized {
245
- type Error = !;
246
-
241
+ pub trait TypeFolder < ' tcx > : FallibleTypeFolder < ' tcx , Error = !> {
247
242
fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > ;
248
243
249
244
fn fold_binder < T > ( & mut self , t : Binder < ' tcx , T > ) -> Binder < ' tcx , T >
250
245
where
251
246
T : TypeFoldable < ' tcx > ,
252
- Self : TypeFolder < ' tcx , Error = !> ,
253
247
{
254
248
t. super_fold_with ( self )
255
249
}
256
250
257
- fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx >
258
- where
259
- Self : TypeFolder < ' tcx , Error = !> ,
260
- {
251
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
261
252
t. super_fold_with ( self )
262
253
}
263
254
264
- fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx >
265
- where
266
- Self : TypeFolder < ' tcx , Error = !> ,
267
- {
255
+ fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
268
256
r. super_fold_with ( self )
269
257
}
270
258
271
- fn fold_const ( & mut self , c : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx >
272
- where
273
- Self : TypeFolder < ' tcx , Error = !> ,
274
- {
259
+ fn fold_const ( & mut self , c : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
275
260
c. super_fold_with ( self )
276
261
}
277
262
278
- fn fold_unevaluated ( & mut self , uv : ty:: Unevaluated < ' tcx > ) -> ty:: Unevaluated < ' tcx >
279
- where
280
- Self : TypeFolder < ' tcx , Error = !> ,
281
- {
263
+ fn fold_unevaluated ( & mut self , uv : ty:: Unevaluated < ' tcx > ) -> ty:: Unevaluated < ' tcx > {
282
264
uv. super_fold_with ( self )
283
265
}
284
266
285
- fn fold_predicate ( & mut self , p : ty:: Predicate < ' tcx > ) -> ty:: Predicate < ' tcx >
286
- where
287
- Self : TypeFolder < ' tcx , Error = !> ,
288
- {
267
+ fn fold_predicate ( & mut self , p : ty:: Predicate < ' tcx > ) -> ty:: Predicate < ' tcx > {
289
268
p. super_fold_with ( self )
290
269
}
291
270
292
- fn fold_mir_const ( & mut self , c : mir:: ConstantKind < ' tcx > ) -> mir:: ConstantKind < ' tcx >
293
- where
294
- Self : TypeFolder < ' tcx , Error = !> ,
295
- {
271
+ fn fold_mir_const ( & mut self , c : mir:: ConstantKind < ' tcx > ) -> mir:: ConstantKind < ' tcx > {
296
272
bug ! ( "most type folders should not be folding MIR datastructures: {:?}" , c)
297
273
}
298
274
}
@@ -304,7 +280,11 @@ pub trait TypeFolder<'tcx>: Sized {
304
280
/// A blanket implementation of this trait (that defers to the relevant
305
281
/// method of [`TypeFolder`]) is provided for all infallible folders in
306
282
/// order to ensure the two APIs are coherent.
307
- pub trait FallibleTypeFolder < ' tcx > : TypeFolder < ' tcx > {
283
+ pub trait FallibleTypeFolder < ' tcx > : Sized {
284
+ type Error ;
285
+
286
+ fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > ;
287
+
308
288
fn try_fold_binder < T > ( & mut self , t : Binder < ' tcx , T > ) -> Result < Binder < ' tcx , T > , Self :: Error >
309
289
where
310
290
T : TypeFoldable < ' tcx > ,
@@ -350,45 +330,48 @@ pub trait FallibleTypeFolder<'tcx>: TypeFolder<'tcx> {
350
330
// delegates to infallible methods to ensure coherence.
351
331
impl < ' tcx , F > FallibleTypeFolder < ' tcx > for F
352
332
where
353
- F : TypeFolder < ' tcx , Error = ! > ,
333
+ F : TypeFolder < ' tcx > ,
354
334
{
355
- fn try_fold_binder < T > ( & mut self , t : Binder < ' tcx , T > ) -> Result < Binder < ' tcx , T > , Self :: Error >
335
+ type Error = !;
336
+
337
+ fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' tcx > {
338
+ TypeFolder :: tcx ( self )
339
+ }
340
+
341
+ fn try_fold_binder < T > ( & mut self , t : Binder < ' tcx , T > ) -> Result < Binder < ' tcx , T > , !>
356
342
where
357
343
T : TypeFoldable < ' tcx > ,
358
344
{
359
345
Ok ( self . fold_binder ( t) )
360
346
}
361
347
362
- fn try_fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , Self :: Error > {
348
+ fn try_fold_ty ( & mut self , t : Ty < ' tcx > ) -> Result < Ty < ' tcx > , ! > {
363
349
Ok ( self . fold_ty ( t) )
364
350
}
365
351
366
- fn try_fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> Result < ty:: Region < ' tcx > , Self :: Error > {
352
+ fn try_fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> Result < ty:: Region < ' tcx > , ! > {
367
353
Ok ( self . fold_region ( r) )
368
354
}
369
355
370
- fn try_fold_const ( & mut self , c : ty:: Const < ' tcx > ) -> Result < ty:: Const < ' tcx > , Self :: Error > {
356
+ fn try_fold_const ( & mut self , c : ty:: Const < ' tcx > ) -> Result < ty:: Const < ' tcx > , ! > {
371
357
Ok ( self . fold_const ( c) )
372
358
}
373
359
374
360
fn try_fold_unevaluated (
375
361
& mut self ,
376
362
c : ty:: Unevaluated < ' tcx > ,
377
- ) -> Result < ty:: Unevaluated < ' tcx > , Self :: Error > {
363
+ ) -> Result < ty:: Unevaluated < ' tcx > , ! > {
378
364
Ok ( self . fold_unevaluated ( c) )
379
365
}
380
366
381
- fn try_fold_predicate (
382
- & mut self ,
383
- p : ty:: Predicate < ' tcx > ,
384
- ) -> Result < ty:: Predicate < ' tcx > , Self :: Error > {
367
+ fn try_fold_predicate ( & mut self , p : ty:: Predicate < ' tcx > ) -> Result < ty:: Predicate < ' tcx > , !> {
385
368
Ok ( self . fold_predicate ( p) )
386
369
}
387
370
388
371
fn try_fold_mir_const (
389
372
& mut self ,
390
373
c : mir:: ConstantKind < ' tcx > ,
391
- ) -> Result < mir:: ConstantKind < ' tcx > , Self :: Error > {
374
+ ) -> Result < mir:: ConstantKind < ' tcx > , ! > {
392
375
Ok ( self . fold_mir_const ( c) )
393
376
}
394
377
}
0 commit comments