Skip to content

Commit 7b9d7fc

Browse files
committed
sembr
1 parent 5d8e19f commit 7b9d7fc

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/doc/rustc-dev-guide/src/ty-fold.md

+13-19
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ and
1616
- `TypeFolder` defines what you want to do with the types you encounter while processing the
1717
`TypeFoldable`.
1818

19-
For example, the `TypeFolder` trait has a method
20-
[`fold_ty`]
21-
that takes a type as input and returns a new type as a result. `TypeFoldable` invokes the
22-
`TypeFolder` `fold_foo` methods on itself, giving the `TypeFolder` access to its contents (the
23-
types, regions, etc that are contained within).
19+
For example, the `TypeFolder` trait has a method [`fold_ty`]
20+
that takes a type as input and returns a new type as a result.
21+
`TypeFoldable` invokes the `TypeFolder` `fold_foo` methods on itself,
22+
giving the `TypeFolder` access to its contents (the types, regions, etc that are contained within).
2423

2524
You can think of it with this analogy to the iterator combinators we have come to love in Rust:
2625

@@ -35,8 +34,7 @@ So to reiterate:
3534
- `TypeFolder` is a trait that defines a “map” operation.
3635
- `TypeFoldable` is a trait that is implemented by things that embed types.
3736

38-
In the case of `subst`, we can see that it is implemented as a `TypeFolder`:
39-
[`ArgFolder`].
37+
In the case of `subst`, we can see that it is implemented as a `TypeFolder`: [`ArgFolder`].
4038
Looking at its implementation, we see where the actual substitutions are happening.
4139

4240
However, you might also notice that the implementation calls this `super_fold_with` method. What is
@@ -90,18 +88,14 @@ things. We only want to do something when we reach a type. That means there may
9088
`TypeFoldable` types whose implementations basically just forward to their fields’ `TypeFoldable`
9189
implementations. Such implementations of `TypeFoldable` tend to be pretty tedious to write by hand.
9290
For this reason, there is a `derive` macro that allows you to `#![derive(TypeFoldable)]`. It is
93-
defined
94-
[here].
95-
96-
**`subst`** In the case of substitutions the [actual
97-
folder]
98-
is going to be doing the indexing we’ve already mentioned. There we define a `Folder` and call
99-
`fold_with` on the `TypeFoldable` to process yourself. Then
100-
[fold_ty]
101-
the method that process each type it looks for a `ty::Param` and for those it replaces it for
102-
something from the list of substitutions, otherwise recursively process the type. To replace it,
103-
calls
104-
[ty_for_param]
91+
defined [here].
92+
93+
**`subst`** In the case of substitutions the [actual folder]
94+
is going to be doing the indexing we’ve already mentioned.
95+
There we define a `Folder` and call `fold_with` on the `TypeFoldable` to process yourself.
96+
Then [fold_ty] the method that process each type it looks for a `ty::Param` and for those
97+
it replaces it for something from the list of substitutions, otherwise recursively process the type.
98+
To replace it, calls [ty_for_param]
10599
and all that does is index into the list of substitutions with the index of the `Param`.
106100

107101
[a previous chapter]: ty_module/instantiating_binders.md

0 commit comments

Comments
 (0)