Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4e067e8

Browse files
committedMar 8, 2022
Improve rustdoc book
1 parent b97dc20 commit 4e067e8

13 files changed

+106
-83
lines changed
 

‎src/doc/rustdoc/book.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ title = "The rustdoc book"
44

55
[output.html]
66
git-repository-url = "https://github.com/rust-lang/rust/tree/master/src/doc/rustdoc"
7+
8+
[output.html.redirect]
9+
"/the-doc-attribute.html" = "write-documentation/the-doc-attribute.html"
10+
"/documentation-tests.html" = "write-documentation/documentation-tests.html"

‎src/doc/rustdoc/src/SUMMARY.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# The Rustdoc Book
22

33
- [What is rustdoc?](what-is-rustdoc.md)
4+
- [Command-line arguments](command-line-arguments.md)
45
- [How to read rustdoc output](how-to-read-rustdoc.md)
56
- [How to write documentation](how-to-write-documentation.md)
6-
- [What to include (and exclude)](what-to-include.md)
7-
- [Command-line arguments](command-line-arguments.md)
8-
- [The `#[doc]` attribute](the-doc-attribute.md)
9-
- [Documentation tests](documentation-tests.md)
10-
- [Linking to items by name](linking-to-items-by-name.md)
11-
- [Lints](lints.md)
7+
- [What to include (and exclude)](write-documentation/what-to-include.md)
8+
- [The `#[doc]` attribute](write-documentation/the-doc-attribute.md)
9+
- [Linking to items by name](write-documentation/linking-to-items-by-name.md)
10+
- [Documentation tests](write-documentation/documentation-tests.md)
11+
- [Rustdoc-specific lints](lints.md)
1212
- [Advanced features](advanced-features.md)
1313
- [Unstable features](unstable-features.md)
14-
- [Website features](website-features.md)
15-
- [Passes](passes.md)
14+
- [Deprecated features](deprecated-features.md)
1615
- [References](references.md)

‎src/doc/rustdoc/src/advanced-features.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,25 @@ You can add multiple aliases at the same time by using a list:
8888
#[doc(alias("x", "big"))]
8989
pub struct BigX;
9090
```
91+
92+
## Custom search engines
93+
94+
If you find yourself often referencing online Rust docs you might enjoy using a custom search
95+
engine. This allows you to use the navigation bar directly to search a `rustdoc` website.
96+
Most browsers support this feature by letting you define a URL template containing `%s`
97+
which will be substituted for the search term. As an example, for the standard library you could use
98+
this template:
99+
100+
```text
101+
https://doc.rust-lang.org/stable/std/?search=%s
102+
```
103+
104+
Note that this will take you to a results page listing all matches. If you want to navigate to the first
105+
result right away (which is often the best match) use the following instead:
106+
107+
```text
108+
https://doc.rust-lang.org/stable/std/?search=%s&go_to_first=true
109+
```
110+
111+
This URL adds the `go_to_first=true` query parameter which can be appended to any `rustdoc` search URL
112+
to automatically go to the first result.

‎src/doc/rustdoc/src/command-line-arguments.md

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ $ rustdoc src/lib.rs --test
177177
```
178178

179179
This flag will run your code examples as tests. For more, see [the chapter
180-
on documentation tests](documentation-tests.md).
180+
on documentation tests](write-documentation/documentation-tests.md).
181181

182182
See also `--test-args`.
183183

@@ -190,7 +190,7 @@ $ rustdoc src/lib.rs --test --test-args ignored
190190
```
191191

192192
This flag will pass options to the test runner when running documentation tests.
193-
For more, see [the chapter on documentation tests](documentation-tests.md).
193+
For more, see [the chapter on documentation tests](write-documentation/documentation-tests.md).
194194

195195
See also `--test`.
196196

@@ -336,7 +336,7 @@ $ rustdoc src/lib.rs --sysroot /path/to/sysroot
336336
Similar to `rustc --sysroot`, this lets you change the sysroot `rustdoc` uses
337337
when compiling your code.
338338

339-
### `--edition`: control the edition of docs and doctests
339+
## `--edition`: control the edition of docs and doctests
340340

341341
Using this flag looks like this:
342342

@@ -403,12 +403,12 @@ encoded as UTF-8.
403403
## `--passes`: add more rustdoc passes
404404

405405
This flag is **deprecated**.
406-
For more details on passes, see [the chapter on them](passes.md).
406+
For more details on passes, see [the chapter on them](deprecated-features.md#passes).
407407

408408
## `--no-defaults`: don't run default passes
409409

410410
This flag is **deprecated**.
411-
For more details on passes, see [the chapter on them](passes.md).
411+
For more details on passes, see [the chapter on them](deprecated-features.md#passes).
412412

413413
## `-r`/`--input-format`: input format
414414

@@ -417,23 +417,3 @@ This flag is **deprecated** and **has no effect**.
417417
Rustdoc only supports Rust source code and Markdown input formats. If the
418418
file ends in `.md` or `.markdown`, `rustdoc` treats it as a Markdown file.
419419
Otherwise, it assumes that the input file is Rust.
420-
421-
# Unstable command line arguments
422-
423-
## `--nocapture`
424-
425-
When this flag is used with `--test`, the output (stdout and stderr) of your tests won't be
426-
captured by rustdoc. Instead, the output will be directed to your terminal,
427-
as if you had run the test executable manually. This is especially useful
428-
for debugging your tests!
429-
430-
## `--check`
431-
432-
When this flag is supplied, rustdoc will type check and lint your code, but will not generate any
433-
documentation or run your doctests.
434-
435-
Using this flag looks like:
436-
437-
```bash
438-
rustdoc -Z unstable-options --check src/lib.rs
439-
```

‎src/doc/rustdoc/src/passes.md renamed to ‎src/doc/rustdoc/src/deprecated-features.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Passes
1+
# Deprecated features
2+
3+
## Passes
24

35
Rustdoc has a concept called "passes". These are transformations that
46
`rustdoc` runs on your documentation before producing its final output.

‎src/doc/rustdoc/src/how-to-read-rustdoc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ At the top is some at-a-glance info and controls:
2626
- a button to collapse or expand the top-level documentation for that item
2727
(`[+]` or `[-]`),
2828
- a link to the source code (`[src]`),
29-
if [configured](the-doc-attribute.html#html_no_source),
29+
if [configured](write-documentation/the-doc-attribute.html#html_no_source),
3030
and present (the source may not be available if
3131
the documentation was created with `cargo doc --no-deps`),
3232
- and the version in which the item became stable,
@@ -52,7 +52,7 @@ For example, when looking at documentation for the crate root,
5252
it shows all the crates documented in the documentation bundle,
5353
and quick links to the modules, structs, traits, functions, and macros available
5454
from the current crate.
55-
At the top, it displays a [configurable logo](the-doc-attribute.html#html_logo_url)
55+
At the top, it displays a [configurable logo](write-documentation/the-doc-attribute.html#html_logo_url)
5656
alongside the current crate's name and version,
5757
or the current item whose documentation is being displayed.
5858

‎src/doc/rustdoc/src/lints.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Note that, except for `missing_docs`, these lints are only available when runnin
1313

1414
Here is the list of the lints provided by `rustdoc`:
1515

16-
## broken_intra_doc_links
16+
## `broken_intra_doc_links`
1717

1818
This lint **warns by default**. This lint detects when an [intra-doc link] fails to be resolved. For example:
1919

20-
[intra-doc link]: linking-to-items-by-name.md
20+
[intra-doc link]: write-documentation/linking-to-items-by-name.md
2121

2222
```rust
2323
/// I want to link to [`Nonexistent`] but it doesn't exist!
@@ -64,7 +64,7 @@ help: to link to the function, add parentheses
6464
6565
```
6666

67-
## private_intra_doc_links
67+
## `private_intra_doc_links`
6868

6969
This lint **warns by default**. This lint detects when [intra-doc links] from public to private items.
7070
For example:
@@ -104,9 +104,9 @@ warning: public documentation for `public` links to private item `private`
104104
= note: this link resolves only because you passed `--document-private-items`, but will break without
105105
```
106106

107-
[intra-doc links]: linking-to-items-by-name.html
107+
[intra-doc links]: write-documentation/linking-to-items-by-name.md
108108

109-
## missing_docs
109+
## `missing_docs`
110110

111111
This lint is **allowed by default**. It detects items missing documentation.
112112
For example:
@@ -130,7 +130,7 @@ warning: missing documentation for a function
130130

131131
Note that unlike other rustdoc lints, this lint is also available from `rustc` directly.
132132

133-
## missing_crate_level_docs
133+
## `missing_crate_level_docs`
134134

135135
This lint is **allowed by default**. It detects if there is no documentation
136136
at the crate root. For example:
@@ -154,7 +154,7 @@ warning in the future. This is intended as a means to introduce new users on
154154
get started, without providing overwhelming warnings like `missing_docs`
155155
might.
156156

157-
## missing_doc_code_examples
157+
## `missing_doc_code_examples`
158158

159159
This lint is **allowed by default** and is **nightly-only**. It detects when a documentation block
160160
is missing a code example. For example:
@@ -190,7 +190,7 @@ To fix the lint, you need to add a code example into the documentation block:
190190
pub fn no_code_example() {}
191191
```
192192

193-
## private_doc_tests
193+
## `private_doc_tests`
194194

195195
This lint is **allowed by default**. It detects documentation tests when they
196196
are on a private item. For example:
@@ -223,7 +223,7 @@ warning: Documentation test in private item
223223
| |___________^
224224
```
225225

226-
## invalid_codeblock_attributes
226+
## `invalid_codeblock_attributes`
227227

228228
This lint **warns by default**. It detects code block attributes in
229229
documentation examples that have potentially mis-typed values. For example:
@@ -259,7 +259,7 @@ warning: unknown attribute `should-panic`. Did you mean `should_panic`?
259259
In the example above, the correct form is `should_panic`. This helps detect
260260
typo mistakes for some common attributes.
261261

262-
## invalid_html_tags
262+
## `invalid_html_tags`
263263

264264
This lint is **allowed by default** and is **nightly-only**. It detects unclosed
265265
or invalid HTML tags. For example:
@@ -298,7 +298,7 @@ warning: unclosed HTML tag `h1`
298298
warning: 2 warnings emitted
299299
```
300300

301-
## invalid_rust_codeblocks
301+
## `invalid_rust_codeblocks`
302302

303303
This lint **warns by default**. It detects Rust code blocks in documentation
304304
examples that are invalid (e.g. empty, not parsable as Rust). For example:
@@ -342,7 +342,7 @@ warning: could not parse code block as Rust code
342342
= note: error from rustc: unterminated character literal
343343
```
344344

345-
## bare_urls
345+
## `bare_urls`
346346

347347
This lint is **warn-by-default**. It detects URLs which are not links.
348348
For example:

‎src/doc/rustdoc/src/unstable-features.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ As detailed in [the chapter on documentation tests][doctest-attributes], you can
2222
nightly, you can optionally add an error number to state that a doctest should emit a specific error
2323
number:
2424

25-
[doctest-attributes]: documentation-tests.html#attributes
25+
[doctest-attributes]: write-documentation/documentation-tests.html#attributes
2626

2727
``````markdown
2828
```compile_fail,E0044
@@ -45,6 +45,8 @@ and enabled with a `#![feature(...)]` attribute in your crate.
4545

4646
### `#[doc(cfg)]`: Recording what platforms or features are required for code to be present
4747

48+
* Tracking issue: [#43781](https://github.com/rust-lang/rust/issues/43781)
49+
4850
You can use `#[doc(cfg(...))]` to tell Rustdoc exactly which platform items appear on.
4951
This has two effects:
5052

@@ -86,6 +88,8 @@ Book][unstable-doc-cfg] and [its tracking issue][issue-doc-cfg].
8688

8789
### `doc_auto_cfg`: Automatically generate `#[doc(cfg)]`
8890

91+
* Tracking issue: [#43781](https://github.com/rust-lang/rust/issues/43781)
92+
8993
`doc_auto_cfg` is an extension to the `#[doc(cfg)]` feature. With it, you don't need to add
9094
`#[doc(cfg(...)]` anymore unless you want to override the default behaviour. So if we take the
9195
previous source code:
@@ -123,6 +127,8 @@ And `doc` won't show up anymore!
123127

124128
### Adding your trait to the "Notable traits" dialog
125129

130+
* Tracking issue: [#45040](https://github.com/rust-lang/rust/issues/45040)
131+
126132
Rustdoc keeps a list of a few traits that are believed to be "fundamental" to
127133
types that implement them. These traits are intended to be the primary interface
128134
for their implementers, and are often most of the API available to be documented
@@ -146,6 +152,8 @@ and [its tracking issue][issue-notable_trait].
146152

147153
### Exclude certain dependencies from documentation
148154

155+
* Tracking issue: [#44027](https://github.com/rust-lang/rust/issues/44027)
156+
149157
The standard library uses several dependencies which, in turn, use several types and traits from the
150158
standard library. In addition, there are several compiler-internal crates that are not considered to
151159
be part of the official standard library, and thus would be a distraction to include in
@@ -164,8 +172,7 @@ Book][unstable-masked] and [its tracking issue][issue-masked].
164172
[unstable-masked]: ../unstable-book/language-features/doc-masked.html
165173
[issue-masked]: https://github.com/rust-lang/rust/issues/44027
166174

167-
168-
## Document primitives
175+
### Document primitives
169176

170177
This is for Rust compiler internal use only.
171178

@@ -174,7 +181,7 @@ attributes. The `#[doc(primitive)]` attribute is used by the standard library to
174181
to generate documentation for primitive types, and requires `#![feature(rustdoc_internals)]` to
175182
enable.
176183

177-
## Document keywords
184+
### Document keywords
178185

179186
This is for Rust compiler internal use only.
180187

@@ -199,6 +206,8 @@ the flag in question to Rustdoc on the command-line. To do this from Cargo, you
199206

200207
### `--markdown-before-content`: include rendered Markdown before the content
201208

209+
* Tracking issue: [#44027](https://github.com/rust-lang/rust/issues/44027)
210+
202211
Using this flag looks like this:
203212

204213
```bash
@@ -241,7 +250,7 @@ attribute][doc-playground]. Please be aware that the official Rust Playground at
241250
https://play.rust-lang.org does not have every crate available, so if your examples require your
242251
crate, make sure the playground you provide has your crate available.
243252

244-
[doc-playground]: the-doc-attribute.html#html_playground_url
253+
[doc-playground]: write-documentation/the-doc-attribute.html#html_playground_url
245254

246255
If both `--playground-url` and `--markdown-playground-url` are present when rendering a standalone
247256
Markdown file, the URL given to `--markdown-playground-url` will take precedence. If both
@@ -279,6 +288,8 @@ between compilations.
279288

280289
### `--resource-suffix`: modifying the name of CSS/JavaScript in crate docs
281290

291+
* Tracking issue: [#54765](https://github.com/rust-lang/rust/issues/54765)
292+
282293
Using this flag looks like this:
283294

284295
```bash
@@ -331,6 +342,24 @@ Using `index-page` option enables `enable-index-page` option as well.
331342

332343
This feature allows the generation of a default index-page which lists the generated crates.
333344

345+
### `--nocapture`: disable output capture for test
346+
347+
When this flag is used with `--test`, the output (stdout and stderr) of your tests won't be
348+
captured by rustdoc. Instead, the output will be directed to your terminal,
349+
as if you had run the test executable manually. This is especially useful
350+
for debugging your tests!
351+
352+
### `--check`: only checks the documentation
353+
354+
When this flag is supplied, rustdoc will type check and lint your code, but will not generate any
355+
documentation or run your doctests.
356+
357+
Using this flag looks like:
358+
359+
```bash
360+
rustdoc -Z unstable-options --check src/lib.rs
361+
```
362+
334363
### `--static-root-path`: control how static files are loaded in HTML output
335364

336365
Using this flag looks like this:
@@ -348,6 +377,8 @@ renamed with `--resource-suffix` will load from the given path.
348377

349378
### `--persist-doctests`: persist doctest executables after running
350379

380+
* Tracking issue: [#56925](https://github.com/rust-lang/rust/issues/56925)
381+
351382
Using this flag looks like this:
352383

353384
```bash
@@ -360,6 +391,8 @@ with this option, you can keep those binaries around for farther testing.
360391

361392
### `--show-coverage`: calculate the percentage of items with documentation
362393

394+
* Tracking issue: [#58154](https://github.com/rust-lang/rust/issues/58154)
395+
363396
Using this flag looks like this:
364397

365398
```bash
@@ -438,6 +471,8 @@ information.
438471

439472
### `--enable-per-target-ignores`: allow `ignore-foo` style filters for doctests
440473

474+
* Tracking issue: [#64245](https://github.com/rust-lang/rust/issues/64245)
475+
441476
Using this flag looks like this:
442477

443478
```bash
@@ -471,6 +506,8 @@ override `ignore`.
471506

472507
### `--runtool`, `--runtool-arg`: program to run tests with; args to pass to it
473508

509+
* Tracking issue: [#64245](https://github.com/rust-lang/rust/issues/64245)
510+
474511
Using these options looks like this:
475512

476513
```bash
@@ -488,6 +525,8 @@ Another use case would be to run a test inside an emulator, or through a Virtual
488525

489526
### `--with-examples`: include examples of uses of items as documentation
490527

528+
* Tracking issue: [#88791](https://github.com/rust-lang/rust/issues/88791)
529+
491530
This option, combined with `--scrape-examples-target-crate` and
492531
`--scrape-examples-output-path`, is used to implement the functionality in [RFC
493532
#3123](https://github.com/rust-lang/rfcs/pull/3123). Uses of an item (currently
@@ -515,6 +554,8 @@ add the `--scrape-tests` flag.
515554

516555
### `--check-cfg`: check configuration flags
517556

557+
* Tracking issue: [#82450](https://github.com/rust-lang/rust/issues/82450)
558+
518559
This flag accepts the same values as `rustc --check-cfg`, and uses it to check configuration flags.
519560

520561
Using this flag looks like this:

‎src/doc/rustdoc/src/website-features.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎src/doc/rustdoc/src/documentation-tests.md renamed to ‎src/doc/rustdoc/src/write-documentation/documentation-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ By default, this will still hide `unused` warnings, since so many examples use p
269269
you can add `#![warn(unused)]` to the top of your example if you want to see unused variables or dead code warnings.
270270
You can also use [`#![doc(test(attr(warn(unused))))]`][test-attr] in the crate root to enable warnings globally.
271271

272-
[test-attr]: ./the-doc-attribute.md#testattr
272+
[test-attr]: the-doc-attribute.md#testattr
273273

274274
## Documenting macros
275275

‎src/doc/rustdoc/src/linking-to-items-by-name.md renamed to ‎src/doc/rustdoc/src/write-documentation/linking-to-items-by-name.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ link to `Option`.
3535
You can refer to anything in scope, and use paths, including `Self`, `self`, `super`, and
3636
`crate`. Associated items (functions, types, and constants) are supported, but [not for blanket
3737
trait implementations][#79682]. Rustdoc also supports linking to all primitives listed in
38-
[the standard library documentation](../std/index.html#primitives).
38+
[the standard library documentation](../../std/index.html#primitives).
3939

4040
[#79682]: https://github.com/rust-lang/rust/pull/79682
4141

‎src/doc/rustdoc/src/the-doc-attribute.md renamed to ‎src/doc/rustdoc/src/write-documentation/the-doc-attribute.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ but given that docs are rendered via Markdown, it will remove these newlines.
3838
Another use case is for including external files as documentation:
3939

4040
```rust,no_run
41-
#[doc = include_str!("../README.md")]
41+
#[doc = include_str!("../../README.md")]
4242
# fn f() {}
4343
```
4444

@@ -73,7 +73,7 @@ left hand side of the docs.
7373
#![doc(html_logo_url = "https://example.com/logo.jpg")]
7474
```
7575

76-
This will put `<a href='index.html'><img src='{}' alt='logo' width='100'></a>` into
76+
This will put `<a href='../index.html'><img src='{}' alt='logo' width='100'></a>` into
7777
your docs, where the string for the attribute goes into the `{}`.
7878

7979
If you don't use this attribute, there will be no logo.

‎src/doc/rustdoc/src/what-to-include.md renamed to ‎src/doc/rustdoc/src/write-documentation/what-to-include.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ Here is an example of a new theme, [Ayu].
122122
[API Guidelines]: https://rust-lang.github.io/api-guidelines/documentation.html#rustdoc-does-not-show-unhelpful-implementation-details-c-hidden
123123
[Documentation tests]: documentation-tests.md
124124
[on this blog]: https://blog.guillaume-gomez.fr/articles/2016-09-16+Generating+doc+with+rustdoc+and+a+custom+theme
125-
[rustdoc-lints]: lints.md
125+
[rustdoc-lints]: ../lints.md

0 commit comments

Comments
 (0)
Please sign in to comment.