Skip to content

Commit 41920f7

Browse files
committed
sembr src/rustdoc.md
1 parent a15dfa1 commit 41920f7

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

src/rustdoc.md

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
# Rustdoc overview
22

3-
`rustdoc` lives in-tree with the
4-
compiler and standard library. This chapter is about how it works.
3+
`rustdoc` lives in-tree with the compiler and standard library.
4+
This chapter is about how it works.
55
For information about Rustdoc's features and how to use them, see
66
the [Rustdoc book](https://doc.rust-lang.org/nightly/rustdoc/).
7-
For more details about how rustdoc works, see the
8-
["Rustdoc internals" chapter][Rustdoc internals].
7+
For more details about how rustdoc works, see the ["Rustdoc internals" chapter][Rustdoc internals].
98

109
[Rustdoc internals]: ./rustdoc-internals.md
1110

1211
`rustdoc` uses `rustc` internals (and, of course, the standard library), so you
1312
will have to build the compiler and `std` once before you can build `rustdoc`.
1413

15-
Rustdoc is implemented entirely within the crate [`librustdoc`][rd]. It runs
16-
the compiler up to the point where we have an internal representation of a
17-
crate (HIR) and the ability to run some queries about the types of items. [HIR]
18-
and [queries] are discussed in the linked chapters.
14+
Rustdoc is implemented entirely within the crate [`librustdoc`][rd].
15+
It runs the compiler up to the point where we have an internal representation of a
16+
crate (HIR) and the ability to run some queries about the types of items.
17+
[HIR] and [queries] are discussed in the linked chapters.
1918

2019
[HIR]: ./hir.md
2120
[queries]: ./query.md
2221
[rd]: https://github.com/rust-lang/rust/tree/HEAD/src/librustdoc
2322

24-
`librustdoc` performs two major steps after that to render a set of
25-
documentation:
23+
`librustdoc` performs two major steps after that to render a set of documentation:
2624

2725
* "Clean" the AST into a form that's more suited to creating documentation (and
2826
slightly more resistant to churn in the compiler).
@@ -31,9 +29,9 @@ documentation:
3129
Naturally, there's more than just this, and those descriptions simplify out
3230
lots of details, but that's the high-level overview.
3331

34-
(Side note: `librustdoc` is a library crate! The `rustdoc` binary is created
35-
using the project in [`src/tools/rustdoc`][bin]. Note that literally all that
36-
does is call the `main()` that's in this crate's `lib.rs`, though.)
32+
(Side note: `librustdoc` is a library crate!
33+
The `rustdoc` binary is created using the project in [`src/tools/rustdoc`][bin].
34+
Note that literally all that does is call the `main()` that's in this crate's `lib.rs`, though.)
3735

3836
[bin]: https://github.com/rust-lang/rust/tree/HEAD/src/tools/rustdoc
3937

@@ -47,15 +45,14 @@ does is call the `main()` that's in this crate's `lib.rs`, though.)
4745
rustdoc you can run on other projects.
4846
* Add `library/test` to be able to use `rustdoc --test`.
4947
* Run `rustup toolchain link stage2 build/host/stage2` to add a
50-
custom toolchain called `stage2` to your rustup environment. After
51-
running that, `cargo +stage2 doc` in any directory will build with
48+
custom toolchain called `stage2` to your rustup environment.
49+
After running that, `cargo +stage2 doc` in any directory will build with
5250
your locally-compiled rustdoc.
5351
* Use `./x doc library` to use this rustdoc to generate the
5452
standard library docs.
5553
* The completed docs will be available in `build/host/doc` (under `core`, `alloc`, and `std`).
5654
* If you want to copy those docs to a webserver, copy all of
57-
`build/host/doc`, since that's where the CSS, JS, fonts, and landing
58-
page are.
55+
`build/host/doc`, since that's where the CSS, JS, fonts, and landing page are.
5956
* For frontend debugging, disable the `rust.docs-minification` option in [`bootstrap.toml`].
6057
* Use `./x test tests/rustdoc*` to run the tests using a stage1
6158
rustdoc.
@@ -65,7 +62,8 @@ does is call the `main()` that's in this crate's `lib.rs`, though.)
6562
6663
### JavaScript CI checks
6764

68-
Rustdoc’s JavaScript and TypeScript are checked during CI by `eslint`, `es-check`, and `tsc` (not by compiletest). These run as part of the `tidy` job.
65+
Rustdoc’s JavaScript and TypeScript are checked during CI by `eslint`, `es-check`, and `tsc` (not by compiletest).
66+
These run as part of the `tidy` job.
6967

7068
```bash
7169
./x.py test tidy --extra-checks=js
@@ -103,22 +101,24 @@ See [Rustdoc tests suites](tests/compiletest.md#rustdoc-test-suites) for more de
103101

104102
## Constraints
105103

106-
We try to make rustdoc work reasonably well with JavaScript disabled, and when
107-
browsing local files. We support
104+
We try to make rustdoc work reasonably well with JavaScript disabled, and when browsing local files.
105+
We support
108106
[these browsers](https://rust-lang.github.io/rfcs/1985-tiered-browser-support.html#supported-browsers).
109107

110108
Supporting local files (`file:///` URLs) brings some surprising restrictions.
111109
Certain browser features that require secure origins, like `localStorage` and
112-
Service Workers, don't work reliably. We can still use such features but we
113-
should make sure pages are still usable without them.
110+
Service Workers, don't work reliably.
111+
We can still use such features but we should make sure pages are still usable without them.
114112

115113
Rustdoc [does not type-check function bodies][platform-specific docs].
116114
This works by [overriding the built-in queries for typeck][override queries],
117115
by [silencing name resolution errors], and by [not resolving opaque types].
118116
This comes with several caveats: in particular, rustdoc *cannot* run any parts of the compiler that
119-
require type-checking bodies; for example it cannot generate `.rlib` files or run most lints.
117+
require type-checking bodies;
118+
for example it cannot generate `.rlib` files or run most lints.
120119
We want to move away from this model eventually, but we need some alternative for
121-
[the people using it][async-std]; see [various][zulip stop accepting broken code]
120+
[the people using it][async-std];
121+
see [various][zulip stop accepting broken code]
122122
[previous][rustdoc meeting 2024-07-08] [Zulip][compiler meeting 2023-01-26] [discussion][notriddle rfc].
123123
For examples of code that breaks if this hack is removed, see
124124
[`tests/rustdoc-ui/error-in-impl-trait`].
@@ -136,9 +136,9 @@ For examples of code that breaks if this hack is removed, see
136136

137137
## Multiple runs, same output directory
138138

139-
Rustdoc can be run multiple times for varying inputs, with its output set to the
140-
same directory. That's how cargo produces documentation for dependencies of the
141-
current crate. It can also be done manually if a user wants a big
139+
Rustdoc can be run multiple times for varying inputs, with its output set to the same directory.
140+
That's how cargo produces documentation for dependencies of the current crate.
141+
It can also be done manually if a user wants a big
142142
documentation bundle with all of the docs they care about.
143143

144144
HTML is generated independently for each crate, but there is some cross-crate
@@ -147,68 +147,68 @@ information that we update as we add crates to the output directory:
147147
- `crates<SUFFIX>.js` holds a list of all crates in the output directory.
148148
- `search-index<SUFFIX>.js` holds a list of all searchable items.
149149
- For each trait, there is a file under `implementors/.../trait.TraitName.js`
150-
containing a list of implementors of that trait. The implementors may be in
151-
different crates than the trait, and the JS file is updated as we discover
152-
new ones.
150+
containing a list of implementors of that trait.
151+
The implementors may be in
152+
different crates than the trait, and the JS file is updated as we discover new ones.
153153

154154
## Use cases
155155

156-
There are a few major use cases for rustdoc that you should keep in mind when
157-
working on it:
156+
There are a few major use cases for rustdoc that you should keep in mind when working on it:
158157

159158
### Standard library docs
160159

161-
These are published at <https://doc.rust-lang.org/std> as part of the Rust release
162-
process. Stable releases are also uploaded to specific versioned URLs like
163-
<https://doc.rust-lang.org/1.57.0/std/>. Beta and nightly docs are published to
160+
These are published at <https://doc.rust-lang.org/std> as part of the Rust release process.
161+
Stable releases are also uploaded to specific versioned URLs like
162+
<https://doc.rust-lang.org/1.57.0/std/>.
163+
Beta and nightly docs are published to
164164
<https://doc.rust-lang.org/beta/std/> and <https://doc.rust-lang.org/nightly/std/>.
165165
The docs are uploaded with the [promote-release
166-
tool](https://github.com/rust-lang/promote-release) and served from S3 with
167-
CloudFront.
166+
tool](https://github.com/rust-lang/promote-release) and served from S3 with CloudFront.
168167

169-
The standard library docs contain five crates: alloc, core, proc_macro, std, and
170-
test.
168+
The standard library docs contain five crates: alloc, core, proc_macro, std, and test.
171169

172170
### docs.rs
173171

174172
When crates are published to crates.io, docs.rs automatically builds
175-
and publishes their documentation, for instance at
176-
<https://docs.rs/serde/latest/serde/>. It always builds with the current nightly
173+
and publishes their documentation, for instance at <https://docs.rs/serde/latest/serde/>.
174+
It always builds with the current nightly
177175
rustdoc, so any changes you land in rustdoc are "insta-stable" in that they will
178-
have an immediate public effect on docs.rs. Old documentation is only sometimes rebuilt, so
179-
you will see some variation in UI when browsing old releases in docs.rs. Crate
180-
authors can request rebuilds, which will be run with the latest rustdoc.
176+
have an immediate public effect on docs.rs.
177+
Old documentation is only sometimes rebuilt, so
178+
you will see some variation in UI when browsing old releases in docs.rs.
179+
Crate authors can request rebuilds, which will be run with the latest rustdoc.
181180

182181
Docs.rs performs some transformations on rustdoc's output in order to save
183-
storage and display a navigation bar at the top. In particular, certain static
182+
storage and display a navigation bar at the top.
183+
In particular, certain static
184184
files, like main.js and rustdoc.css, may be shared across multiple invocations
185-
of the same version of rustdoc. Others, like crates.js and sidebar-items.js, are
186-
different for different invocations. Still others, like fonts, will never
187-
change. These categories are distinguished using the `SharedResource` enum in
185+
of the same version of rustdoc.
186+
Others, like crates.js and sidebar-items.js, are different for different invocations.
187+
Still others, like fonts, will never change.
188+
These categories are distinguished using the `SharedResource` enum in
188189
`src/librustdoc/html/render/write_shared.rs`
189190

190191
Documentation on docs.rs is always generated for a single crate at a time, so
191-
the search and sidebar functionality don't include dependencies of the current
192-
crate.
192+
the search and sidebar functionality don't include dependencies of the current crate.
193193

194194
### Locally generated docs
195195

196-
Crate authors can run `cargo doc --open` in crates they have checked
197-
out locally to see the docs. This is useful to check that the docs they
198-
are writing are useful and display correctly. It can also be useful for
199-
people to view documentation on crates they aren't authors of, but want to
200-
use. In both cases, people may use `--document-private-items` Cargo flag to
196+
Crate authors can run `cargo doc --open` in crates they have checked out locally to see the docs.
197+
This is useful to check that the docs they are writing are useful and display correctly.
198+
It can also be useful for people to view documentation on crates they aren't authors of, but want to
199+
use.
200+
In both cases, people may use `--document-private-items` Cargo flag to
201201
see private methods, fields, and so on, which are normally not displayed.
202202

203-
By default `cargo doc` will generate documentation for a crate and all of its
204-
dependencies. That can result in a very large documentation bundle, with a large
205-
(and slow) search corpus. The Cargo flag `--no-deps` inhibits that behavior and
206-
generates docs for just the crate.
203+
By default `cargo doc` will generate documentation for a crate and all of its dependencies.
204+
That can result in a very large documentation bundle, with a large (and slow) search corpus.
205+
The Cargo flag `--no-deps` inhibits that behavior and generates docs for just the crate.
207206

208207
### Self-hosted project docs
209208

210-
Some projects like to host their own documentation. For example:
211-
<https://docs.serde.rs/>. This is easy to do by locally generating docs, and
212-
simply copying them to a web server. Rustdoc's HTML output can be extensively
213-
customized by flags. Users can add a theme, set the default theme, and inject
214-
arbitrary HTML. See `rustdoc --help` for details.
209+
Some projects like to host their own documentation.
210+
For example: <https://docs.serde.rs/>.
211+
This is easy to do by locally generating docs, and simply copying them to a web server.
212+
Rustdoc's HTML output can be extensively customized by flags.
213+
Users can add a theme, set the default theme, and inject arbitrary HTML.
214+
See `rustdoc --help` for details.

0 commit comments

Comments
 (0)