-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Write the "passes" chapter of the rustdoc book #43790
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,86 @@ | ||
# Passes | ||
|
||
Coming soon! | ||
Rustdoc has a concept called "passes". These are transformations that | ||
`rustdoc` runs on your documentation before producing its final output. | ||
|
||
In addition to the passes below, check out the docs for these flags: | ||
|
||
* [`--passes`](command-line-arguments.html#--passes-add-more-rustdoc-passes) | ||
* [`--no-defaults`](command-line-arguments.html#--no-defaults-dont-run-default-passes) | ||
|
||
## Default passes | ||
|
||
By default, rustdoc will run some passes, namely: | ||
|
||
* `strip-hidden` | ||
* `strip-private` | ||
* `collapse-docs` | ||
* `unindent-comments` | ||
|
||
However, `strip-private` implies `strip-private-imports`, and so effectively, | ||
all passes are run by default. | ||
|
||
## `strip-hidden` | ||
|
||
This pass implements the `#[doc(hidden)]` attribute. When this pass runs, it | ||
checks each item, and if it is annotated with this attribute, it removes it | ||
from `rustdoc`'s output. | ||
|
||
Without this pass, these items will remain in the output. | ||
|
||
## `unindent-comments` | ||
|
||
When you write a doc comment like this: | ||
|
||
```rust,ignore | ||
/// This is a documentation comment. | ||
``` | ||
|
||
There's a space between the `///` and that `T`. That spacing isn't intended | ||
to be a part of the output; it's there for humans, to help separate the doc | ||
comment syntax from the text of the comment. This pass is what removes that | ||
space. | ||
|
||
The exact rules are left under-specified so that we can fix issues that we find. | ||
|
||
Without this pass, the exact number of spaces is preserved. | ||
|
||
## `collapse-docs` | ||
|
||
With this pass, multiple `#[doc]` attributes are converted into one single | ||
documentation string. | ||
|
||
For example: | ||
|
||
```rust,ignore | ||
#[doc = "This is the first line."] | ||
#[doc = "This is the second line."] | ||
``` | ||
|
||
Gets collapsed into a single doc string of | ||
|
||
```text | ||
This is the first line. | ||
This is the second line. | ||
``` | ||
|
||
## `strip-private` | ||
|
||
This removes documentation for any non-public items, so for example: | ||
|
||
```rust,ignore | ||
/// These are private docs. | ||
struct Private; | ||
|
||
/// These are public docs. | ||
pub struct Public; | ||
``` | ||
|
||
This pass removes the docs for `Private`, since they're not public. | ||
|
||
This pass implies `strip-priv-imports`. | ||
|
||
## `strip-priv-imports` | ||
|
||
This is the same as `strip-private`, but for `extern crate` and `use` | ||
statements instead of items. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line confuses me. Is this pass anything more complex than removing a single space if it exists? Are we not able to fix issues if we specify the rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, just saw this was approved. Don't block this PR on my comment here, but feel free to answer if there's an answer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current semantics are a bit awkward to specify completely, see the thread at #43790 (comment) for a brief summary. I think the thought for stating this was that if we describe everything it does then it would create a situation where either we get penned in by the current implementation, or the docs inevitably get out of sync when we patch around various issues.