Skip to content

Commit d725da1

Browse files
committed
Clean up and improve some docs
* compiler docs * Don't format list as part of a code block * Clean up some other formatting * rustdoc book * Update CommonMark spec version to latest (0.28 -> 0.29) * Clean up some various wording and formatting
1 parent b1496c6 commit d725da1

File tree

3 files changed

+58
-32
lines changed

3 files changed

+58
-32
lines changed

compiler/rustc_middle/src/middle/region.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,20 @@ pub struct ScopeTree {
292292
///
293293
/// Then:
294294
///
295-
/// 1. From the ordering guarantee of HIR visitors (see
296-
/// `rustc_hir::intravisit`), `D` does not dominate `U`.
295+
/// 1. From the ordering guarantee of HIR visitors (see
296+
/// `rustc_hir::intravisit`), `D` does not dominate `U`.
297297
///
298-
/// 2. Therefore, `D` is *potentially* storage-dead at `U` (because
299-
/// we might visit `U` without ever getting to `D`).
298+
/// 2. Therefore, `D` is *potentially* storage-dead at `U` (because
299+
/// we might visit `U` without ever getting to `D`).
300300
///
301-
/// 3. However, we guarantee that at each HIR point, each
302-
/// binding/temporary is always either always storage-live
303-
/// or always storage-dead. This is what is being guaranteed
304-
/// by `terminating_scopes` including all blocks where the
305-
/// count of executions is not guaranteed.
301+
/// 3. However, we guarantee that at each HIR point, each
302+
/// binding/temporary is always either always storage-live
303+
/// or always storage-dead. This is what is being guaranteed
304+
/// by `terminating_scopes` including all blocks where the
305+
/// count of executions is not guaranteed.
306306
///
307-
/// 4. By `2.` and `3.`, `D` is *statically* storage-dead at `U`,
308-
/// QED.
307+
/// 4. By `2.` and `3.`, `D` is *statically* storage-dead at `U`,
308+
/// QED.
309309
///
310310
/// This property ought to not on (3) in an essential way -- it
311311
/// is probably still correct even if we have "unrestricted" terminating

compiler/rustc_mir_build/src/thir/pattern/_match.rs

+32-8
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,26 @@
7878
//! new pattern `p`.
7979
//!
8080
//! For example, say we have the following:
81+
//!
8182
//! ```
82-
//! // x: (Option<bool>, Result<()>)
83-
//! match x {
84-
//! (Some(true), _) => {}
85-
//! (None, Err(())) => {}
86-
//! (None, Err(_)) => {}
87-
//! }
83+
//! // x: (Option<bool>, Result<()>)
84+
//! match x {
85+
//! (Some(true), _) => {}
86+
//! (None, Err(())) => {}
87+
//! (None, Err(_)) => {}
88+
//! }
8889
//! ```
90+
//!
8991
//! Here, the matrix `P` starts as:
92+
//!
93+
//! ```
9094
//! [
9195
//! [(Some(true), _)],
9296
//! [(None, Err(()))],
9397
//! [(None, Err(_))],
9498
//! ]
99+
//! ```
100+
//!
95101
//! We can tell it's not exhaustive, because `U(P, _)` is true (we're not covering
96102
//! `[(Some(false), _)]`, for instance). In addition, row 3 is not useful, because
97103
//! all the values it covers are already covered by row 2.
@@ -178,10 +184,14 @@
178184
//! This special case is handled in `is_useful_specialized`.
179185
//!
180186
//! For example, if `P` is:
187+
//!
188+
//! ```
181189
//! [
182-
//! [Some(true), _],
183-
//! [None, 0],
190+
//! [Some(true), _],
191+
//! [None, 0],
184192
//! ]
193+
//! ```
194+
//!
185195
//! and `p` is [Some(false), 0], then we don't care about row 2 since we know `p` only
186196
//! matches values that row 2 doesn't. For row 1 however, we need to dig into the
187197
//! arguments of `Some` to know whether some new value is covered. So we compute
@@ -198,10 +208,14 @@
198208
//! `U(P, p) := U(D(P), D(p))`
199209
//!
200210
//! For example, if `P` is:
211+
//!
212+
//! ```
201213
//! [
202214
//! [_, true, _],
203215
//! [None, false, 1],
204216
//! ]
217+
//! ```
218+
//!
205219
//! and `p` is [_, false, _], the `Some` constructor doesn't appear in `P`. So if we
206220
//! only had row 2, we'd know that `p` is useful. However row 1 starts with a
207221
//! wildcard, so we need to check whether `U([[true, _]], [false, 1])`.
@@ -215,10 +229,14 @@
215229
//! `U(P, p) := ∃(k ϵ constructors) U(S(k, P), S(k, p))`
216230
//!
217231
//! For example, if `P` is:
232+
//!
233+
//! ```
218234
//! [
219235
//! [Some(true), _],
220236
//! [None, false],
221237
//! ]
238+
//! ```
239+
//!
222240
//! and `p` is [_, false], both `None` and `Some` constructors appear in the first
223241
//! components of `P`. We will therefore try popping both constructors in turn: we
224242
//! compute `U([[true, _]], [_, false])` for the `Some` constructor, and `U([[false]],
@@ -1496,6 +1514,7 @@ struct PatCtxt<'tcx> {
14961514
/// multiple patterns.
14971515
///
14981516
/// For example, if we are constructing a witness for the match against
1517+
///
14991518
/// ```
15001519
/// struct Pair(Option<(u32, u32)>, bool);
15011520
///
@@ -1619,12 +1638,14 @@ fn all_constructors<'a, 'tcx>(
16191638
// actually match against them all themselves. So we always return only the fictitious
16201639
// constructor.
16211640
// E.g., in an example like:
1641+
//
16221642
// ```
16231643
// let err: io::ErrorKind = ...;
16241644
// match err {
16251645
// io::ErrorKind::NotFound => {},
16261646
// }
16271647
// ```
1648+
//
16281649
// we don't want to show every possible IO error, but instead have only `_` as the
16291650
// witness.
16301651
let is_declared_nonexhaustive = cx.is_foreign_non_exhaustive_enum(pcx.ty);
@@ -2017,6 +2038,7 @@ crate fn is_useful<'p, 'tcx>(
20172038
let mut unreachable_branches = Vec::new();
20182039
// Subpatterns that are unreachable from all branches. E.g. in the following case, the last
20192040
// `true` is unreachable only from one branch, so it is overall reachable.
2041+
//
20202042
// ```
20212043
// match (true, true) {
20222044
// (true, true) => {}
@@ -2161,10 +2183,12 @@ crate fn is_useful<'p, 'tcx>(
21612183
// to do this and instead report a single `_` witness:
21622184
// if the user didn't actually specify a constructor
21632185
// in this arm, e.g., in
2186+
//
21642187
// ```
21652188
// let x: (Direction, Direction, bool) = ...;
21662189
// let (_, _, false) = x;
21672190
// ```
2191+
//
21682192
// we don't want to show all 16 possible witnesses
21692193
// `(<direction-1>, <direction-2>, true)` - we are
21702194
// satisfied with `(_, _, true)`. In this case,

src/doc/rustdoc/src/documentation-tests.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ The basic idea is this:
1616
The triple backticks start and end code blocks. If this were in a file named `foo.rs`,
1717
running `rustdoc --test foo.rs` will extract this example, and then run it as a test.
1818

19-
Please note that by default, if no language is set for the block code, `rustdoc`
20-
assumes it is `Rust` code. So the following:
19+
Please note that by default, if no language is set for the block code, rustdoc
20+
assumes it is Rust code. So the following:
2121

2222
``````markdown
2323
```rust
@@ -44,7 +44,6 @@ the `assert!` family of macros works the same as other Rust code:
4444

4545
```rust
4646
let foo = "foo";
47-
4847
assert_eq!(foo, "foo");
4948
```
5049

@@ -55,8 +54,9 @@ the code panics and the doctest fails.
5554

5655
In the example above, you'll note something strange: there's no `main`
5756
function! Forcing you to write `main` for every example, no matter how small,
58-
adds friction. So `rustdoc` processes your examples slightly before
59-
running them. Here's the full algorithm rustdoc uses to preprocess examples:
57+
adds friction and clutters the output. So `rustdoc` processes your examples
58+
slightly before running them. Here's the full algorithm `rustdoc` uses to
59+
preprocess examples:
6060

6161
1. Some common `allow` attributes are inserted, including
6262
`unused_variables`, `unused_assignments`, `unused_mut`,
@@ -78,10 +78,12 @@ Sometimes, you need some setup code, or other things that would distract
7878
from your example, but are important to make the tests work. Consider
7979
an example block that looks like this:
8080

81-
```text
81+
```ignore
82+
/// ```
8283
/// /// Some documentation.
8384
/// # fn foo() {} // this function will be hidden
8485
/// println!("Hello, World!");
86+
/// ```
8587
```
8688

8789
It will render like this:
@@ -251,7 +253,7 @@ disambiguate the error type:
251253
This is an unfortunate consequence of the `?` operator adding an implicit
252254
conversion, so type inference fails because the type is not unique. Please note
253255
that you must write the `(())` in one sequence without intermediate whitespace
254-
so that rustdoc understands you want an implicit `Result`-returning function.
256+
so that `rustdoc` understands you want an implicit `Result`-returning function.
255257

256258
## Documenting macros
257259

@@ -359,7 +361,7 @@ the code with the 2015 edition.
359361
## Syntax reference
360362

361363
The *exact* syntax for code blocks, including the edge cases, can be found
362-
in the [Fenced Code Blocks](https://spec.commonmark.org/0.28/#fenced-code-blocks)
364+
in the [Fenced Code Blocks](https://spec.commonmark.org/0.29/#fenced-code-blocks)
363365
section of the CommonMark specification.
364366

365367
Rustdoc also accepts *indented* code blocks as an alternative to fenced
@@ -372,7 +374,7 @@ can indent each line by four or more spaces.
372374
``````
373375

374376
These, too, are documented in the CommonMark specification, in the
375-
[Indented Code Blocks](https://spec.commonmark.org/0.28/#indented-code-blocks)
377+
[Indented Code Blocks](https://spec.commonmark.org/0.29/#indented-code-blocks)
376378
section.
377379

378380
However, it's preferable to use fenced code blocks over indented code blocks.
@@ -388,7 +390,7 @@ documentation. To this end, Rustdoc allows you to have certain items only appear
388390
collecting doctests, so you can utilize doctest functionality without forcing the test to appear in
389391
docs, or to find an arbitrary private item to include it on.
390392

391-
When compiling a crate for use in doctests (with `--test` option), rustdoc will set `cfg(doctest)`.
393+
When compiling a crate for use in doctests (with `--test` option), `rustdoc` will set `#[cfg(doctest)]`.
392394
Note that they will still link against only the public items of your crate; if you need to test
393395
private items, you need to write a unit test.
394396

@@ -407,18 +409,18 @@ pub struct MyStructOnlyTakesUsize;
407409
```
408410

409411
Note that the struct `MyStructOnlyTakesUsize` here isn't actually part of your public crate
410-
API. The use of `#[cfg(doctest)]` makes sure that this struct only exists while rustdoc is
412+
API. The use of `#[cfg(doctest)]` makes sure that this struct only exists while `rustdoc` is
411413
collecting doctests. This means that its doctest is executed when `--test` is passed to rustdoc,
412414
but is hidden from the public documentation.
413415

414-
Another possible use of `cfg(doctest)` is to test doctests that are included in your README file
416+
Another possible use of `#[cfg(doctest)]` is to test doctests that are included in your README file
415417
without including it in your main documentation. For example, you could write this into your
416418
`lib.rs` to test your README as part of your doctests:
417419

418420
```rust,ignore
419421
#![feature(external_doc)]
420422
421-
#[doc(include="../README.md")]
423+
#[doc(include = "../README.md")]
422424
#[cfg(doctest)]
423425
pub struct ReadmeDoctests;
424426
```

0 commit comments

Comments
 (0)