Skip to content

Commit 96ea984

Browse files
committed
Prepare PR #329 to be merged
We made an editorial pass over this.
1 parent d7a41be commit 96ea984

File tree

3 files changed

+64
-65
lines changed

3 files changed

+64
-65
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@
5656
- [Unsafe `extern` blocks](rust-2024/unsafe-extern.md)
5757
- [Unsafe attributes](rust-2024/unsafe-attributes.md)
5858
- [Rustdoc combined tests](rust-2024/rustdoc-doctests.md)
59+
- [Rustdoc nested `include!` change](rust-2024/rustdoc-nested-includes.md)
5960
- [Reserved syntax](rust-2024/reserved-syntax.md)
60-
- [Rustdoc doctest nested `include_str!` change](rust-2024/rustdoc-doctests-nested-include-str.md)

src/rust-2024/rustdoc-doctests-nested-include-str.md

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Rustdoc nested `include!` change
2+
3+
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
4+
More information may be found in the tracking issue at <https://github.com/rust-lang/rust/issues/132230>.
5+
6+
## Summary
7+
8+
When a doctest is included with `include_str!`, if that doctest itself also uses `include!`, `include_str!`, or `include_bytes!`, the path is resolved relative to the Markdown file, rather than to the Rust source file.
9+
10+
## Details
11+
12+
Prior to the 2024 edition, adding documentation with `#[doc=include_str!("path/file.md")]` didn't carry span information into any doctests in that file. As a result, if the Markdown file was in a different directory than the source, any paths included had to be specified relative to the source file.
13+
14+
For example, consider a library crate with these files:
15+
16+
- `Cargo.toml`
17+
- `README.md`
18+
- `src/`
19+
- `lib.rs`
20+
- `examples/`
21+
- `data.bin`
22+
23+
Let's say that `lib.rs` contains this:
24+
25+
```rust,ignore
26+
#![doc=include_str!("../README.md")]
27+
```
28+
29+
And assume this `README.md` file:
30+
31+
````markdown
32+
```
33+
let _ = include_bytes!("../examples/data.bin");
34+
// ^^^ notice this
35+
```
36+
````
37+
38+
Prior to the 2024 edition, the path in `README.md` needed to be relative to the `lib.rs` file. In 2024 and later, it is now relative to `README.md` itself, so we would update `README.md` to:
39+
40+
````markdown
41+
```
42+
let _ = include_bytes!("examples/data.bin");
43+
```
44+
````
45+
46+
## Migration
47+
48+
There is no automatic migration to convert the paths in affected doctests. If one of your doctests is affected, you'll see an error like this after migrating to the new edition when building your tests:
49+
50+
```text
51+
error: couldn't read `../examples/data.bin`: No such file or directory (os error 2)
52+
--> src/../README.md:2:24
53+
|
54+
2 | let _ = include_bytes!("../examples/data.bin");
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
57+
help: there is a file with the same name in a different directory
58+
|
59+
2 | let _ = include_bytes!("examples/data.bin");
60+
| ~~~~~~~~~~~~~~~~~~~
61+
```
62+
63+
To migrate your doctests to Rust 2024, update any affected paths to be relative to the file containing the doctests.

0 commit comments

Comments
 (0)