@@ -17,8 +17,8 @@ pub use self::subst::Subst;
17
17
/// certain changes applied. The idea is that it contains methods that
18
18
/// let you swap types/lifetimes for new types/lifetimes; meanwhile,
19
19
/// each bit of IR implements the `TypeFoldable` trait which, given a
20
- /// `TypeFolder `, will reconstruct itself, invoking the folder's methods
21
- /// to transform each of the types/lifetimes embedded within.
20
+ /// `FallibleTypeFolder `, will reconstruct itself, invoking the folder's
21
+ /// methods to transform each of the types/lifetimes embedded within.
22
22
///
23
23
/// # Usage patterns
24
24
///
@@ -29,15 +29,15 @@ pub use self::subst::Subst;
29
29
/// more often, just free existential variables) that appear within
30
30
/// the term.
31
31
///
32
- /// For this reason, the `TypeFolder ` trait extends two other traits that
33
- /// contain methods that are invoked when just those particular
32
+ /// For this reason, the `FallibleTypeFolder ` trait extends two other
33
+ /// traits that contain methods that are invoked when just those particular
34
34
///
35
35
/// In particular, folders can intercept references to free variables
36
36
/// (either existentially or universally quantified) and replace them
37
37
/// with other types/lifetimes as appropriate.
38
38
///
39
- /// To create a folder `F`, one never implements `TypeFolder` directly, but instead
40
- /// implements one of each of these three sub-traits:
39
+ /// To create a folder `F`, one never implements `FallibleTypeFolder`
40
+ /// directly, but instead implements one of each of these three sub-traits:
41
41
///
42
42
/// - `FreeVarFolder` -- folds `BoundVar` instances that appear free
43
43
/// in the term being folded (use `DefaultFreeVarFolder` to
@@ -49,24 +49,25 @@ pub use self::subst::Subst;
49
49
/// that appear in the term being folded (use
50
50
/// `DefaultPlaceholderFolder` to ignore/forbid these altogether)
51
51
///
52
- /// To **apply** a folder, use the `TypeFoldable::fold_with` method, like so
52
+ /// To **apply** a folder, use the `TypeFoldable::fold_with` method,
53
+ /// like so
53
54
///
54
55
/// ```rust,ignore
55
56
/// let x = x.fold_with(&mut folder, 0);
56
57
/// ```
57
- pub trait TypeFolder < I : Interner > {
58
+ pub trait FallibleTypeFolder < I : Interner > {
58
59
/// The type this folder returns when folding fails. This is
59
60
/// commonly [`NoSolution`].
60
61
type Error ;
61
62
62
63
/// Creates a `dyn` value from this folder. Unfortunately, this
63
- /// must be added manually to each impl of TypeFolder ; it permits the
64
- /// default implements below to create a `&mut dyn TypeFolder` from
65
- /// `Self` without knowing what `Self` is (by invoking this
66
- /// method). Effectively, this limits impls of `TypeFolder` to types
67
- /// for which we are able to create a dyn value (i.e., not `[T]`
68
- /// types).
69
- fn as_dyn ( & mut self ) -> & mut dyn TypeFolder < I , Error = Self :: Error > ;
64
+ /// must be added manually to each impl of FallibleTypeFolder ; it
65
+ /// permits the default implements below to create a
66
+ /// `&mut dyn FallibleTypeFolder` from `Self` without knowing what
67
+ /// `Self` is (by invoking this method). Effectively, this limits
68
+ /// impls of `FallibleTypeFolder` to types for which we are able to
69
+ /// create a dyn value (i.e., not `[T]` types).
70
+ fn as_dyn ( & mut self ) -> & mut dyn FallibleTypeFolder < I , Error = Self :: Error > ;
70
71
71
72
/// Top-level callback: invoked for each `Ty<I>` that is
72
73
/// encountered when folding. By default, invokes
@@ -318,7 +319,7 @@ pub trait TypeFoldable<I: Interner>: Debug + Sized {
318
319
/// constructs.
319
320
fn fold_with < E > (
320
321
self ,
321
- folder : & mut dyn TypeFolder < I , Error = E > ,
322
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
322
323
outer_binder : DebruijnIndex ,
323
324
) -> Result < Self , E > ;
324
325
}
@@ -330,7 +331,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
330
331
/// Recursively folds the value.
331
332
fn super_fold_with < E > (
332
333
self ,
333
- folder : & mut dyn TypeFolder < I , Error = E > ,
334
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
334
335
outer_binder : DebruijnIndex ,
335
336
) -> Result < Self , E > ;
336
337
}
@@ -341,7 +342,7 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
341
342
impl < I : Interner > TypeFoldable < I > for Ty < I > {
342
343
fn fold_with < E > (
343
344
self ,
344
- folder : & mut dyn TypeFolder < I , Error = E > ,
345
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
345
346
outer_binder : DebruijnIndex ,
346
347
) -> Result < Self , E > {
347
348
folder. fold_ty ( self , outer_binder)
@@ -355,7 +356,7 @@ where
355
356
{
356
357
fn super_fold_with < E > (
357
358
self ,
358
- folder : & mut dyn TypeFolder < I , Error = E > ,
359
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
359
360
outer_binder : DebruijnIndex ,
360
361
) -> Result < Ty < I > , E > {
361
362
let interner = folder. interner ( ) ;
@@ -463,7 +464,7 @@ where
463
464
impl < I : Interner > TypeFoldable < I > for Lifetime < I > {
464
465
fn fold_with < E > (
465
466
self ,
466
- folder : & mut dyn TypeFolder < I , Error = E > ,
467
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
467
468
outer_binder : DebruijnIndex ,
468
469
) -> Result < Self , E > {
469
470
folder. fold_lifetime ( self , outer_binder)
@@ -476,7 +477,7 @@ where
476
477
{
477
478
fn super_fold_with < E > (
478
479
self ,
479
- folder : & mut dyn TypeFolder < I , Error = E > ,
480
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
480
481
outer_binder : DebruijnIndex ,
481
482
) -> Result < Lifetime < I > , E > {
482
483
let interner = folder. interner ( ) ;
@@ -513,7 +514,7 @@ where
513
514
impl < I : Interner > TypeFoldable < I > for Const < I > {
514
515
fn fold_with < E > (
515
516
self ,
516
- folder : & mut dyn TypeFolder < I , Error = E > ,
517
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
517
518
outer_binder : DebruijnIndex ,
518
519
) -> Result < Self , E > {
519
520
folder. fold_const ( self , outer_binder)
@@ -526,7 +527,7 @@ where
526
527
{
527
528
fn super_fold_with < E > (
528
529
self ,
529
- folder : & mut dyn TypeFolder < I , Error = E > ,
530
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
530
531
outer_binder : DebruijnIndex ,
531
532
) -> Result < Const < I > , E > {
532
533
let interner = folder. interner ( ) ;
@@ -562,7 +563,7 @@ where
562
563
impl < I : Interner > TypeFoldable < I > for Goal < I > {
563
564
fn fold_with < E > (
564
565
self ,
565
- folder : & mut dyn TypeFolder < I , Error = E > ,
566
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
566
567
outer_binder : DebruijnIndex ,
567
568
) -> Result < Self , E > {
568
569
folder. fold_goal ( self , outer_binder)
@@ -573,7 +574,7 @@ impl<I: Interner> TypeFoldable<I> for Goal<I> {
573
574
impl < I : Interner > TypeSuperFoldable < I > for Goal < I > {
574
575
fn super_fold_with < E > (
575
576
self ,
576
- folder : & mut dyn TypeFolder < I , Error = E > ,
577
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
577
578
outer_binder : DebruijnIndex ,
578
579
) -> Result < Self , E > {
579
580
let interner = folder. interner ( ) ;
@@ -592,7 +593,7 @@ impl<I: Interner> TypeSuperFoldable<I> for Goal<I> {
592
593
impl < I : Interner > TypeFoldable < I > for ProgramClause < I > {
593
594
fn fold_with < E > (
594
595
self ,
595
- folder : & mut dyn TypeFolder < I , Error = E > ,
596
+ folder : & mut dyn FallibleTypeFolder < I , Error = E > ,
596
597
outer_binder : DebruijnIndex ,
597
598
) -> Result < Self , E > {
598
599
folder. fold_program_clause ( self , outer_binder)
0 commit comments