|
16 | 16 | //! - Types of interest, for which the methods delegate to the folder.
|
17 | 17 | //! - All other types, including generic containers like `Vec` and `Option`.
|
18 | 18 | //! It defines a "skeleton" of how they should be folded.
|
19 |
| -//! - `TypeSuperFoldable`. This is implemented only for each type of interest, |
20 |
| -//! and defines the folding "skeleton" for these types. |
| 19 | +//! - `TypeSuperFoldable`. This is implemented only for recursive types of |
| 20 | +//! interest, and defines the folding "skeleton" for these types. (This |
| 21 | +//! excludes `Region` because it is non-recursive, i.e. it never contains |
| 22 | +//! other types of interest.) |
21 | 23 | //! - `TypeFolder`/`FallibleTypeFolder`. One of these is implemented for each
|
22 | 24 | //! folder. This defines how types of interest are folded.
|
23 | 25 | //!
|
@@ -72,9 +74,9 @@ pub trait TypeFoldable<I: Interner>: TypeVisitable<I> {
|
72 | 74 |
|
73 | 75 | // This trait is implemented for types of interest.
|
74 | 76 | pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
|
75 |
| - /// Provides a default fold for a type of interest. This should only be |
76 |
| - /// called within `TypeFolder` methods, when a non-custom traversal is |
77 |
| - /// desired for the value of the type of interest passed to that method. |
| 77 | + /// Provides a default fold for a recursive type of interest. This should |
| 78 | + /// only be called within `TypeFolder` methods, when a non-custom traversal |
| 79 | + /// is desired for the value of the type of interest passed to that method. |
78 | 80 | /// For example, in `MyFolder::try_fold_ty(ty)`, it is valid to call
|
79 | 81 | /// `ty.try_super_fold_with(self)`, but any other folding should be done
|
80 | 82 | /// with `xyz.try_fold_with(self)`.
|
@@ -118,11 +120,11 @@ pub trait TypeFolder<I: Interner>: FallibleTypeFolder<I, Error = !> {
|
118 | 120 | t.super_fold_with(self)
|
119 | 121 | }
|
120 | 122 |
|
121 |
| - fn fold_region(&mut self, r: I::Region) -> I::Region |
122 |
| - where |
123 |
| - I::Region: TypeSuperFoldable<I>, |
124 |
| - { |
125 |
| - r.super_fold_with(self) |
| 123 | + // The default region folder is a no-op because `Region` is non-recursive |
| 124 | + // and has no `super_visit_with` method to call. That also explains the |
| 125 | + // lack of `I::Region: TypeSuperFoldable<I>` bound on this method. |
| 126 | + fn fold_region(&mut self, r: I::Region) -> I::Region { |
| 127 | + r |
126 | 128 | }
|
127 | 129 |
|
128 | 130 | fn fold_const(&mut self, c: I::Const) -> I::Const
|
@@ -167,11 +169,11 @@ pub trait FallibleTypeFolder<I: Interner>: Sized {
|
167 | 169 | t.try_super_fold_with(self)
|
168 | 170 | }
|
169 | 171 |
|
170 |
| - fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, Self::Error> |
171 |
| - where |
172 |
| - I::Region: TypeSuperFoldable<I>, |
173 |
| - { |
174 |
| - r.try_super_fold_with(self) |
| 172 | + // The default region folder is a no-op because `Region` is non-recursive |
| 173 | + // and has no `super_visit_with` method to call. That also explains the |
| 174 | + // lack of `I::Region: TypeSuperFoldable<I>` bound on this method. |
| 175 | + fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, Self::Error> { |
| 176 | + Ok(r) |
175 | 177 | }
|
176 | 178 |
|
177 | 179 | fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Self::Error>
|
@@ -216,10 +218,7 @@ where
|
216 | 218 | Ok(self.fold_ty(t))
|
217 | 219 | }
|
218 | 220 |
|
219 |
| - fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, !> |
220 |
| - where |
221 |
| - I::Region: TypeSuperFoldable<I>, |
222 |
| - { |
| 221 | + fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, !> { |
223 | 222 | Ok(self.fold_region(r))
|
224 | 223 | }
|
225 | 224 |
|
|
0 commit comments