Skip to content

Commit c4e0c4d

Browse files
committed
Update rustdoc passes documentation
Align the rustdoc internals guide with the current pass definitions and execution order so the documented names, conditions, and coverage behavior match the source.
1 parent 912f6c6 commit c4e0c4d

1 file changed

Lines changed: 33 additions & 53 deletions

File tree

src/rustdoc-internals.md

Lines changed: 33 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -93,65 +93,45 @@ which describe the publicly-documentable items in the target crate.
9393
### Passes Anything But a Gas Station (or: [Hot Potato](https://www.youtube.com/watch?v=WNFBIt5HxdY))
9494

9595
Before moving on to the next major step, a few important "passes" occur over
96-
the cleaned [`AST`][ast].
97-
Several of these passes are `lint`s and reports, but some of them mutate or generate new items.
96+
the cleaned [`AST`][ast]. Several of these passes are `lint`s and reports, but
97+
some of them mutate or generate new items. These are implemented in the
98+
[`librustdoc/passes`] directory, generally one module per pass. Unlike the
99+
previous set of [`AST`][ast] transformations, these passes are run on the
100+
cleaned crate.
98101

99-
These are all implemented in the [`librustdoc/passes`] directory, one file per pass.
100-
By default, all of these passes are run on a crate, but the ones
101-
regarding dropping private/hidden items can be bypassed by passing
102-
`--document-private-items` to `rustdoc`.
103-
Note that, unlike the previous set of [`AST`][ast]
104-
transformations, the passes are run on the _cleaned_ crate.
102+
The source of truth for the available passes is `src/librustdoc/passes/mod.rs`.
103+
In normal documentation builds, `rustdoc` runs `DEFAULT_PASSES`. When
104+
`--show-coverage` is enabled, it instead runs `COVERAGE_PASSES`.
105105

106-
Here is the list of passes as of <!-- date-check --> March 2023:
107-
108-
- `calculate-doc-coverage` calculates information used for the `--show-coverage`
109-
flag.
110-
111-
- `check-doc-test-visibility` runs `doctest` visibility–related `lint`s.
112-
This pass runs before `strip-private`,
113-
which is why it needs to be separate from `run-lints`.
114-
115-
- `collect-intra-doc-links` resolves [intra-doc links](https://doc.rust-lang.org/nightly/rustdoc/write-documentation/linking-to-items-by-name.html).
106+
In normal documentation builds, `rustdoc` runs:
116107

117108
- `collect-trait-impls` collects `trait` `impl`s for each item in the crate.
118-
For example, if we define a `struct` that implements a `trait`,
119-
this pass will note that the `struct` implements that `trait`.
120-
109+
For example, if we define a `struct` that implements a `trait`, this pass
110+
will note that the `struct` implements that `trait`.
111+
- `check_doc_test_visibility` runs `doctest` visibility-related `lint`s. This
112+
pass runs before `strip-private`, which is why it needs to be separate from
113+
`run-lints`.
114+
- `strip-aliased-non-local` strips all non-local private aliased items from the
115+
output.
121116
- `propagate-doc-cfg` propagates `#[doc(cfg(...))]` to child items.
122-
123-
- `run-lints` runs some of `rustdoc`'s `lint`s, defined in `passes/lint`.
124-
This is the last pass to run.
125-
126-
- `bare_urls` detects links that are not linkified, e.g., in Markdown such as
127-
`Go to https://example.com/.` It suggests wrapping the link with angle brackets:
128-
`Go to <https://example.com/>.` to linkify it.
129-
This is the code behind the <!-- date-check: may 2022 --> `rustdoc::bare_urls` `lint`.
130-
131-
- `check_code_block_syntax` validates syntax inside Rust code blocks
132-
(<code>```rust</code>)
133-
134-
- `html_tags` detects invalid `HTML` (like an unclosed `<span>`)
135-
in doc comments.
136-
137-
- `strip-hidden` and `strip-private` strip all `doc(hidden)` and private items
138-
from the output.
139-
`strip-private` implies `strip-priv-imports`.
140-
Basically, the goal is to remove items that are not relevant for public documentation.
141-
This pass is skipped when `--document-hidden-items` is passed.
142-
143-
- `strip-priv-imports` strips all private import statements (`use`, `extern
144-
crate`) from a crate.
145-
This is necessary because `rustdoc` will handle *public*
146-
imports by either inlining the item's documentation to the module or creating
147-
a "Reexports" section with the import in it.
148-
The pass ensures that all of these imports are actually relevant to documentation.
149-
It is technically only run when `--document-private-items` is passed, but `strip-private`
150-
accomplishes the same thing.
151-
117+
- `strip-hidden` strips all `doc(hidden)` items from the output. This pass is
118+
skipped when `--document-hidden-items` is passed.
152119
- `strip-private` strips all private items from a crate which cannot be seen
153-
externally.
154-
This pass is skipped when `--document-private-items` is passed.
120+
externally. This pass is skipped when `--document-private-items` is passed.
121+
- `strip-priv-imports` strips all private import statements (`use`, `extern
122+
crate`) from a crate. This pass only runs when `--document-private-items` is
123+
passed; otherwise `strip-private` covers that case.
124+
- `collect-intra-doc-links` resolves
125+
[intra-doc links](https://doc.rust-lang.org/nightly/rustdoc/write-documentation/linking-to-items-by-name.html).
126+
- `propagate-stability` propagates stability information to child items.
127+
- `run-lints` runs some of `rustdoc`'s `lint`s, defined in `passes/lint`. This
128+
is the last pass to run.
129+
130+
When `--show-coverage` is enabled, `rustdoc` instead runs:
131+
132+
- `strip-hidden`
133+
- `strip-private`
134+
- `calculate-doc-coverage`
155135

156136
There is also a [`stripper`] module in `librustdoc/passes`, but it is a
157137
collection of utility functions for the `strip-*` passes and is not a pass itself.

0 commit comments

Comments
 (0)