Skip to content

rustc-dev-guide subtree update #141026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
May 16, 2025
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
80758c3
add rdg push git config entry for git protocol pushers
May 1, 2025
6e966d7
avoid duplicating commands
May 6, 2025
046bfb3
Preparing for merge from rustc
invalid-email-address May 8, 2025
659f0b6
Merge from rustc
invalid-email-address May 8, 2025
b2de3f4
Merge pull request #2374 from rust-lang/rustc-pull
May 8, 2025
47cd0e7
Fix minor typo in serialization.md
smanilov May 8, 2025
f52e1be
Merge pull request #2375 from smanilov/patch-4
May 8, 2025
d87763d
Remark test naming exception
smanilov May 8, 2025
f31bf4a
Merge pull request #2323 from smanilov/patch-2
BoxyUwU May 8, 2025
a07c71d
Fix minor typo in installation.md
smanilov May 8, 2025
079e0b4
Merge pull request #2377 from smanilov/patch-6
May 8, 2025
3052683
Fix minor typo in rustdoc-internals.md
smanilov May 8, 2025
6831638
Merge pull request #2376 from smanilov/patch-5
May 9, 2025
90ec9da
Merge pull request #2369 from rust-lang/tshepang-patch-1
May 10, 2025
c1de624
link to chapter referred to
May 10, 2025
8c6c97d
use the right case
May 10, 2025
4e684a9
make more clear what is meant
May 10, 2025
9f07c1e
make more readable
May 10, 2025
2efa4e6
sembr
May 10, 2025
eb6749c
is a question
May 10, 2025
a82a329
fix broken links
May 10, 2025
5d8e19f
reduce clutter when reading source
May 10, 2025
7b9d7fc
sembr
May 10, 2025
f1d1ebc
last updated a year ago
May 10, 2025
52e4b4a
add missing word
May 10, 2025
927343e
no point versioning these
May 10, 2025
a9d6551
bump edition
May 10, 2025
63b3bf9
"cargo fmt"
May 10, 2025
58fa975
we are a collective
May 10, 2025
5a406be
noise
May 10, 2025
2a0c72e
Remove obsolete reference to `unsized_tuple_coercion`
Zalathar May 12, 2025
53572cf
Merge pull request #2382 from Zalathar/no-tuple-unsize
JohnTitor May 12, 2025
436c363
Remove n.b. about parser refactoring
smanilov May 9, 2025
e983642
Merge pull request #2378 from smanilov/patch-7
jieyouxu May 12, 2025
b255ae2
remove dangling references
May 12, 2025
032f738
Merge pull request #2383 from rust-lang/tshepang-unused
May 14, 2025
b805dcb
Merge pull request #2380 from rust-lang/tshepang-crate-cleaning
May 14, 2025
30b54ad
Merge pull request #2379 from rust-lang/tshepang-which-chapter
May 14, 2025
05e7ce9
Merge pull request #2373 from rust-lang/tshepang-patch-2
May 14, 2025
5e3aa16
avoid upstream pull conflict
May 15, 2025
d016ed8
Merge pull request #2387 from rust-lang/tshepang-avoid-conflict
May 15, 2025
4adff2f
Preparing for merge from rustc
invalid-email-address May 15, 2025
1fd536c
Merge from rustc
invalid-email-address May 15, 2025
a3ce646
Merge pull request #2388 from rust-lang/rustc-pull
May 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reduce clutter when reading source
  • Loading branch information
Tshepang Mbambo committed May 10, 2025
commit 5d8e19fd152979a887db97a904ac181b6ca5886b
24 changes: 16 additions & 8 deletions src/doc/rustc-dev-guide/src/ty-fold.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ Binders can wrap an arbitrary Rust type `T`, not just a `Ty`.
So, how do we implement the `instantiate` methods on the `Early/Binder` types?

The answer is a couple of traits:
[`TypeFoldable`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/trait.TypeFoldable.html)
[`TypeFoldable`]
and
[`TypeFolder`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/trait.TypeFolder.html).
[`TypeFolder`].

- `TypeFoldable` is implemented by types that embed type information. It allows you to recursively
process the contents of the `TypeFoldable` and do stuff to them.
- `TypeFolder` defines what you want to do with the types you encounter while processing the
`TypeFoldable`.

For example, the `TypeFolder` trait has a method
[`fold_ty`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/trait.TypeFolder.html#method.fold_ty)
[`fold_ty`]
that takes a type as input and returns a new type as a result. `TypeFoldable` invokes the
`TypeFolder` `fold_foo` methods on itself, giving the `TypeFolder` access to its contents (the
types, regions, etc that are contained within).
Expand All @@ -36,7 +36,7 @@ So to reiterate:
- `TypeFoldable` is a trait that is implemented by things that embed types.

In the case of `subst`, we can see that it is implemented as a `TypeFolder`:
[`ArgFolder`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/binder/struct.ArgFolder.html).
[`ArgFolder`].
Looking at its implementation, we see where the actual substitutions are happening.

However, you might also notice that the implementation calls this `super_fold_with` method. What is
Expand Down Expand Up @@ -91,17 +91,25 @@ things. We only want to do something when we reach a type. That means there may
implementations. Such implementations of `TypeFoldable` tend to be pretty tedious to write by hand.
For this reason, there is a `derive` macro that allows you to `#![derive(TypeFoldable)]`. It is
defined
[here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_macros/src/type_foldable.rs).
[here].

**`subst`** In the case of substitutions the [actual
folder](https://github.com/rust-lang/rust/blob/75ff3110ac6d8a0259023b83fd20d7ab295f8dd6/src/librustc_middle/ty/subst.rs#L440-L451)
folder]
is going to be doing the indexing we’ve already mentioned. There we define a `Folder` and call
`fold_with` on the `TypeFoldable` to process yourself. Then
[fold_ty](https://github.com/rust-lang/rust/blob/75ff3110ac6d8a0259023b83fd20d7ab295f8dd6/src/librustc_middle/ty/subst.rs#L512-L536)
[fold_ty]
the method that process each type it looks for a `ty::Param` and for those it replaces it for
something from the list of substitutions, otherwise recursively process the type. To replace it,
calls
[ty_for_param](https://github.com/rust-lang/rust/blob/75ff3110ac6d8a0259023b83fd20d7ab295f8dd6/src/librustc_middle/ty/subst.rs#L552-L587)
[ty_for_param]
and all that does is index into the list of substitutions with the index of the `Param`.

[a previous chapter]: ty_module/instantiating_binders.md
[`TypeFoldable`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/trait.TypeFoldable.html
[`TypeFolder`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/trait.TypeFolder.html
[`fold_ty`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/trait.TypeFolder.html#method.fold_ty
[`ArgFolder`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/binder/struct.ArgFolder.html
[here]: https://github.com/rust-lang/rust/blob/master/compiler/rustc_macros/src/type_foldable.rs
[actual folder]: https://github.com/rust-lang/rust/blob/75ff3110ac6d8a0259023b83fd20d7ab295f8dd6/src/librustc_middle/ty/subst.rs#L440-L451
[fold_ty]: https://github.com/rust-lang/rust/blob/75ff3110ac6d8a0259023b83fd20d7ab295f8dd6/src/librustc_middle/ty/subst.rs#L512-L536
[ty_for_param]: https://github.com/rust-lang/rust/blob/75ff3110ac6d8a0259023b83fd20d7ab295f8dd6/src/librustc_middle/ty/subst.rs#L552-L587