@@ -51,44 +51,81 @@ which describe the publicly-documentable items in the target crate.
51
51
### Hot potato
52
52
53
53
Before moving on to the next major step, a few important "passes" occur over
54
- the documentation. These do things like combine the separate "attributes" into
54
+ the documentation. These do things like combine the separate "attributes" into
55
55
a single string and strip leading whitespace to make the document easier on the
56
56
markdown parser, or drop items that are not public or deliberately hidden with
57
57
` #[doc(hidden)] ` . These are all implemented in the ` passes/ ` directory, one
58
58
file per pass. By default, all of these passes are run on a crate, but the ones
59
59
regarding dropping private/hidden items can be bypassed by passing
60
60
` --document-private-items ` to rustdoc. Note that unlike the previous set of AST
61
- transformations, the passes happen on the _ cleaned_ crate.
61
+ transformations, the passes are run on the _ cleaned_ crate.
62
62
63
63
(Strictly speaking, you can fine-tune the passes run and even add your own, but
64
64
[ we're trying to deprecate that] [ 44136 ] . If you need finer-grain control over
65
65
these passes, please let us know!)
66
66
67
67
[ 44136 ] : https://github.com/rust-lang/rust/issues/44136
68
68
69
- Here is the list of passes as of March 2018 <!-- date: 2018-03 --> :
69
+ Here is the list of passes as of February 2021 <!-- date: 2021-02 --> :
70
+
71
+ - ` calculate-doc-coverage ` calculates information used for the ` --show-coverage `
72
+ flag.
73
+
74
+ - ` check-code-block-syntax ` validates syntax inside Rust code blocks
75
+ (`` ```rust `` )
76
+
77
+ - ` check-invalid-html-tags ` detects invalid HTML (like an unclosed ` <span> ` )
78
+ in doc comments.
79
+
80
+ - ` check-non-autolinks ` detects links that could or should be written using
81
+ angle brackets (the code behind the nightly-only <!-- date: 2021-02 -->
82
+ ` non_autolinks ` lint).
70
83
71
- - ` propagate-doc-cfg ` - propagates ` #[doc(cfg(...))] ` to child items.
72
84
- ` collapse-docs ` concatenates all document attributes into one document
73
85
attribute. This is necessary because each line of a doc comment is given as a
74
86
separate doc attribute, and this will combine them into a single string with
75
87
line breaks between each attribute.
76
- - ` unindent-comments ` removes excess indentation on comments in order for
77
- markdown to like it. This is necessary because the convention for writing
78
- documentation is to provide a space between the ` /// ` or ` //! ` marker and the
79
- text, and stripping that leading space will make the text easier to parse by
80
- the Markdown parser. (In the past, the markdown parser used was not
81
- Commonmark- compliant, which caused annoyances with extra whitespace but this
82
- seems to be less of an issue today.)
88
+
89
+ - ` collect-intra-doc-links ` resolves [ intra-doc links] ( https://doc.rust-lang.org/rustdoc/linking-to-items-by-name.html ) .
90
+
91
+ - ` collect-trait-impls ` collects trait impls for each item in the crate. For
92
+ example, if we define a struct that implements a trait, this pass will note
93
+ that the struct implements that trait.
94
+
95
+ - ` doc-test-lints ` runs various lints on the doctests.
96
+
97
+ - ` propagate-doc-cfg ` propagates ` #[doc(cfg(...))] ` to child items.
98
+
83
99
- ` strip-priv-imports ` strips all private import statements (` use ` , `extern
84
100
crate`) from a crate. This is necessary because rustdoc will handle * public*
85
101
imports by either inlining the item's documentation to the module or creating
86
102
a "Reexports" section with the import in it. The pass ensures that all of
87
103
these imports are actually relevant to documentation.
104
+
88
105
- ` strip-hidden ` and ` strip-private ` strip all ` doc(hidden) ` and private items
89
106
from the output. ` strip-private ` implies ` strip-priv-imports ` . Basically, the
90
107
goal is to remove items that are not relevant for public documentation.
91
108
109
+ - ` unindent-comments ` removes excess indentation on comments in order for the
110
+ Markdown to be parsed correctly. This is necessary because the convention for
111
+ writing documentation is to provide a space between the ` /// ` or ` //! ` marker
112
+ and the doc text, but Markdown is whitespace-sensitive. For example, a block
113
+ of text with four-space indentation is parsed as a code block, so if we didn't
114
+ unindent comments, these list items
115
+
116
+ ``` rust,ignore
117
+ /// A list:
118
+ ///
119
+ /// - Foo
120
+ /// - Bar
121
+ ```
122
+
123
+ would be parsed as if they were in a code block, which is likely not what the
124
+ user intended.
125
+
126
+ There is also a ` stripper ` module in ` passes/ ` , but it is a collection of
127
+ utility functions for the ` strip-* ` passes and is not a pass itself.
128
+
92
129
## From clean to crate
93
130
94
131
This is where the "second phase" in rustdoc begins. This phase primarily lives
@@ -224,4 +261,3 @@ on the internet. For example, the url for `std` will be `/std/".
224
261
225
262
[ `rustdoc` api docs ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/
226
263
[ The rustdoc user guide ] : https://doc.rust-lang.org/nightly/rustdoc/
227
-
0 commit comments