Skip to content

Commit 0386f15

Browse files
committed
Merge PR #329: Fix doctest include paths
2 parents ddb36f5 + 96ea984 commit 0386f15

7 files changed

+174
-3
lines changed

book.toml

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ search.use-boolean-and = true
8080
"/rust-2018/platform-and-target-support/msvc-toolchain-support.html" = "../../../rustc/platform-support.html"
8181
"/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html" = "../../../rustc/platform-support.html"
8282
"/rust-2018/platform-and-target-support/cdylib-crates-for-c-interoperability.html" = "https://github.com/rust-lang/rfcs/blob/master/text/1510-cdylib.md"
83+
"/rust-2021/reserving-syntax.html" = "reserved-syntax.html"
8384
"/rust-next/index.html" = "../rust-2021/index.html"
8485
"/rust-next/edition-changes.html" = "../rust-2021/index.html"
8586
"/rust-next/dbg-macro.html" = "../../std/macro.dbg.html"

src/SUMMARY.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- [IntoIterator for arrays](rust-2021/IntoIterator-for-arrays.md)
3131
- [Disjoint capture in closures](rust-2021/disjoint-capture-in-closures.md)
3232
- [Panic macro consistency](rust-2021/panic-macro-consistency.md)
33-
- [Reserving syntax](rust-2021/reserving-syntax.md)
33+
- [Reserved syntax](rust-2021/reserved-syntax.md)
3434
- [Warnings promoted to errors](rust-2021/warnings-promoted-to-error.md)
3535
- [Or patterns in macro-rules](rust-2021/or-patterns-macro-rules.md)
3636
- [C-string literals](rust-2021/c-string-literals.md)
@@ -44,6 +44,7 @@
4444
- [`unsafe_op_in_unsafe_fn` warning](rust-2024/unsafe-op-in-unsafe-fn.md)
4545
- [RPIT lifetime capture rules](rust-2024/rpit-lifetime-capture.md)
4646
- [Disallow references to `static mut`](rust-2024/static-mut-references.md)
47+
- [Cargo: Rust-version aware resolver](rust-2024/cargo-resolver.md)
4748
- [Cargo: Table and key name consistency](rust-2024/cargo-table-key-names.md)
4849
- [Cargo: Reject unused inherited default-features](rust-2024/cargo-inherited-default-features.md)
4950
- [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md)
@@ -55,3 +56,5 @@
5556
- [Unsafe `extern` blocks](rust-2024/unsafe-extern.md)
5657
- [Unsafe attributes](rust-2024/unsafe-attributes.md)
5758
- [Rustdoc combined tests](rust-2024/rustdoc-doctests.md)
59+
- [Rustdoc nested `include!` change](rust-2024/rustdoc-nested-includes.md)
60+
- [Reserved syntax](rust-2024/reserved-syntax.md)

src/rust-2021/c-string-literals.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ Migration is only necessary for macros which may have been assuming a sequence o
6969
As part of the [syntax reservation] for the 2021 edition, any macro input which may run into this issue should issue a warning from the `rust_2021_prefixes_incompatible_syntax` migration lint.
7070
See that chapter for more detail.
7171

72-
[syntax reservation]: reserving-syntax.md
72+
[syntax reservation]: reserved-syntax.md

src/rust-2021/reserving-syntax.md src/rust-2021/reserved-syntax.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Reserving syntax
1+
# Reserved syntax
22

33
## Summary
44

src/rust-2024/cargo-resolver.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Cargo: Rust-version aware resolver
2+
3+
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
4+
5+
## Summary
6+
7+
- `edition = "2024"` implies `resolver = "3"` in `Cargo.toml` which enables a Rust-version aware dependency resolver.
8+
9+
## Details
10+
11+
Since Rust 1.84.0, Cargo has opt-in support for compatibility with
12+
[`package.rust-version`] to be considered when selecting dependency versions
13+
by setting [`resolver.incompatible-rust-version = "fallback"`] in `.cargo/config.toml`.
14+
15+
Starting in Rust 2024, this will be the default.
16+
That is, writing `edition = "2024"` in `Cargo.toml` will imply `resolver = "3"`
17+
which will imply [`resolver.incompatible-rust-version = "fallback"`].
18+
19+
The resolver is a global setting for a [workspace], and the setting is ignored in dependencies.
20+
The setting is only honored for the top-level package of the workspace.
21+
If you are using a [virtual workspace], you will still need to explicitly set the [`resolver` field]
22+
in the `[workspace]` definition if you want to opt-in to the new resolver.
23+
24+
For more details on how Rust-version aware dependency resolution works, see [the Cargo book](../..//cargo/reference/resolver.html#rust-version).
25+
26+
[`package.rust-version`]: ../../cargo/reference/rust-version.html
27+
[`resolver.incompatible-rust-version = "fallback"`]: ../../cargo/reference/config.html#resolverincompatible-rust-versions
28+
[workspace]: ../../cargo/reference/workspaces.html
29+
[virtual workspace]: ../../cargo/reference/workspaces.html#virtual-workspace
30+
[`resolver` field]: ../../cargo/reference/resolver.html#resolver-versions
31+
32+
## Migration
33+
34+
There are no automated migration tools for updating for the new resolver.
35+
36+
We recommend projects
37+
[verify against the latest dependencies in CI](../../cargo/guide/continuous-integration.html#verifying-latest-dependencies)
38+
to catch bugs in dependencies as soon as possible.

src/rust-2024/reserved-syntax.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Reserved syntax
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/123735>.
5+
6+
## Summary
7+
8+
- Unprefixed guarded strings of the form `#"foo"#` are reserved for future use.
9+
- Two or more `#` characters are reserved for future use.
10+
11+
## Details
12+
13+
[RFC 3593] reserved syntax in the 2024 Edition for guarded string literals that do not have a prefix to make room for possible future language changes. The 2021 Edition [reserved syntax][2021] for guarded strings with a prefix, such as `ident##"foo"##`. The 2024 Edition extends that to also reserve strings without the `ident` prefix.
14+
15+
There are two reserved syntaxes:
16+
17+
- One or more `#` characters immediately followed by a [string literal].
18+
- Two or more `#` characters in a row (not separated by whitespace).
19+
20+
This reservation is done across an edition boundary because of interactions with tokenization and macros. For example, consider this macro:
21+
22+
```rust
23+
macro_rules! demo {
24+
( $a:tt ) => { println!("one token") };
25+
( $a:tt $b:tt $c:tt ) => { println!("three tokens") };
26+
}
27+
28+
demo!("foo");
29+
demo!(r#"foo"#);
30+
demo!(#"foo"#);
31+
demo!(###)
32+
```
33+
34+
Prior to the 2024 Edition, this produces:
35+
36+
```text
37+
one token
38+
one token
39+
three tokens
40+
three tokens
41+
```
42+
43+
Starting in the 2024 Edition, the `#"foo"#` line and the `###` line now generates a compile error because those forms are now reserved.
44+
45+
[2021]: ../rust-2021/reserved-syntax.md
46+
[string literal]: ../../reference/tokens.html#string-literals
47+
[RFC 3593]: https://rust-lang.github.io/rfcs/3593-unprefixed-guarded-strings.html
48+
49+
## Migration
50+
51+
The [`rust_2024_guarded_string_incompatible_syntax`] lint will identify any tokens that match the reserved syntax, and will suggest a modification to insert spaces where necessary to ensure the tokens continue to be parsed separately.
52+
53+
The lint is part of the `rust-2024-compatibility` lint group which is included in the automatic edition migration. In order to migrate your code to be Rust 2024 Edition compatible, run:
54+
55+
```sh
56+
cargo fix --edition
57+
```
58+
59+
Alternatively, you can manually enable the lint to find macro calls where you may need to update the tokens:
60+
61+
```rust
62+
// Add this to the root of your crate to do a manual migration.
63+
#![warn(rust_2024_guarded_string_incompatible_syntax)]
64+
```
65+
66+
[`rust_2024_guarded_string_incompatible_syntax`]: ../../rustc/lints/listing/allowed-by-default.html#rust-2024-guarded-string-incompatible-syntax
+63
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)