Skip to content

Commit 2f7bbef

Browse files
authored
Rollup merge of rust-lang#94753 - Urgau:rustdoc-book-improvements, r=GuillaumeGomez
Improve rustdoc book This pull-request improves the `rustdoc` book by doing some (light) cleanup, by merging some stuff, by adding some missing stuff (like tracking issues links, for those who had one) and also by moving some chapter's into sub-chapter's to improve the flow of the book. ~~Note that I locally tested with `mdbook-lintcheck` that no links became accidentally broken.~~ (Not enough, ;-)) r? ``@GuillaumeGomez``
2 parents 1bacb44 + e346920 commit 2f7bbef

14 files changed

+119
-90
lines changed

src/doc/rustdoc/book.toml

+4
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

+7-8
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

+22
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

+5-25
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 src/doc/rustdoc/src/deprecated-features.md

+3-1
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

+2-2
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

+12-12
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:

0 commit comments

Comments
 (0)