Skip to content

Commit d1a6a44

Browse files
committed
Make some editorial changes
1 parent f5dc745 commit d1a6a44

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/rust-2024/rustdoc-doctests.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ More information may be found in the tracking issue at <https://github.com/rust-
99

1010
## Details
1111

12-
Prior the the 2024 Edition, rustdoc's "test" mode would compile each code block in your documentation as a separate executable. Although this was relatively simple to implement, it resulted in a significant performance burden when there are a large number of documentation tests. Starting with the 2024 Edition, rustdoc will attempt to combine documentation tests into a single binary, significantly reducing the overhead for compiling doctests.
12+
Prior the the 2024 Edition, rustdoc's "test" mode would compile each code block in your documentation as a separate executable. Although this was relatively simple to implement, it resulted in a significant performance burden when there were a large number of documentation tests. Starting with the 2024 Edition, rustdoc will attempt to combine documentation tests into a single binary, significantly reducing the overhead for compiling doctests.
1313

1414
```rust
1515
/// Adds two numbers
@@ -31,26 +31,26 @@ pub fn subtract(left: u64, right: u64) -> u64 {
3131
}
3232
```
3333

34-
In this example, the two doctests will now be compiled in a single executable. Rustdoc will essentially place each example in a separate function within a single binary. The tests still run in independent processes as they did before, so any global state (like global statics) should still continue to work correctly.[^implementation]
34+
In this example, the two doctests will now be compiled into a single executable. Rustdoc will essentially place each example in a separate function within a single binary. The tests still run in independent processes as they did before, so any global state (like global statics) should still continue to work correctly.[^implementation]
3535

3636
This change is only available in the 2024 Edition to avoid potential incompatibilities with existing doctests which may not work in a combined executable. However, these incompatibilities are expected to be extremely rare.
3737

3838
[doctests]: ../../rustdoc/write-documentation/documentation-tests.html
3939
[libtest harness]: ../../rustc/tests/index.html
4040

41-
[^implementation]: For more information on the details of how this work, see [Doctests - How were they improved?](https://blog.guillaume-gomez.fr/articles/2024-08-17+Doctests+-+How+were+they+improved%3F).
41+
[^implementation]: For more information on the details of how this work, see ["Doctests - How were they improved?"](https://blog.guillaume-gomez.fr/articles/2024-08-17+Doctests+-+How+were+they+improved%3F).
4242

4343
### Standalone tag
4444

45-
In some situations it is not possible for rustdoc to combine examples in a single executable. Rustdoc will attempt to automatically detect if this is not possible, for example:
45+
In some situations it is not possible for rustdoc to combine examples into a single executable. Rustdoc will attempt to automatically detect if this is not possible. For example, a test will not be combined with others if it:
4646

47-
* Uses the [`compile_fail`][tags] language tag, which indicates that the example fails to compile.
48-
* Uses the [`edition`][tags], which indicates the edition of the example.[^edition-tag]
49-
* Uses global attributes like the [`global_allocator`] attribute, which could potentially interfere with other tests.
47+
* Uses the [`compile_fail`][tags] tag, which indicates that the example should fail to compile.
48+
* Uses an [`edition`][tags] tag, which indicates the edition of the example.[^edition-tag]
49+
* Uses global attributes, like the [`global_allocator`] attribute, which could potentially interfere with other tests.
5050
* Defines any crate-wide attributes (like `#![feature(...)]`).
5151
* Defines a macro that uses `$crate`, because the `$crate` path will not work correctly.
5252

53-
However, rustdoc is not able to automatically determine *all* situations where an example cannot be combined with other examples. In these situations, you can add the `standalone` language tag to indicate that the example should be built as a separate executable.
53+
However, rustdoc is not able to automatically determine *all* situations where an example cannot be combined with other examples. In these situations, you can add the `standalone` language tag to indicate that the example should be built as a separate executable. For example:
5454

5555
```rust
5656
//! ```
@@ -59,7 +59,7 @@ However, rustdoc is not able to automatically determine *all* situations where a
5959
//! ```
6060
```
6161

62-
This example is sensitive to the code structure of how the example is compiled. This won't work with the "combined" approach because the line numbers will shift depending on how the doctests are combined. In these situations, you can add the `standalone` tag to force the example to be built separately just as it did in previous editions.
62+
This is sensitive to the code structure of how the example is compiled and won't work with the "combined" approach because the line numbers will shift depending on how the doctests are combined. In these situations, you can add the `standalone` tag to force the example to be built separately just as it was in previous editions. E.g.:
6363

6464
```rust
6565
//! ```standalone
@@ -71,8 +71,8 @@ This example is sensitive to the code structure of how the example is compiled.
7171
[tags]: ../../rustdoc/write-documentation/documentation-tests.html#attributes
7272
[`global_allocator`]: ../../std/alloc/trait.GlobalAlloc.html
7373

74-
[^edition-tag]: Note that rustdoc will only combine tests if the entire crate is Edition 2024 or greater. Using `edition2024` tags in older editions will not result in those tests being combined.
74+
[^edition-tag]: Note that rustdoc will only combine tests if the entire crate is Edition 2024 or greater. Using the `edition2024` tag in older editions will not result in those tests being combined.
7575

7676
## Migration
7777

78-
There is no automatic migration to determine which doctests need to be annotated with the `standalone` tag. It's very unlikely that doctests will not work correctly when merged. The only way to know is to update your crate to the 2024 Edition and then run your documentation tests and see if any of them fail. If they do fail, you will need to analyze whether the test can be rewritten to be compatible with the combined approach, or add the `standalone` tag to retain the previous behavior.
78+
There is no automatic migration to determine which doctests need to be annotated with the `standalone` tag. It's very unlikely that any given doctest will not work correctly when migrated. We suggest that you update your crate to the 2024 Edition and then run your documentation tests and see if any fail. If one does, you will need to analyze whether it can be rewritten to be compatible with the combined approach, or alternatively, add the `standalone` tag to retain the previous behavior.

0 commit comments

Comments
 (0)