Skip to content

Commit 9deb096

Browse files
Merge pull request #117 from TonalidadeHidrica/2024/index
[2024] 各項目の目次を翻訳
2 parents a10d0e9 + 16f9616 commit 9deb096

35 files changed

+3267
-3
lines changed

src/SUMMARY.md

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
2-
# The Edition Guide
2+
# The Rust Edition Guide
33
-->
4-
# エディションガイド
4+
# Rust エディションガイド
55

66
<!--
77
[Introduction](introduction.md)
@@ -56,9 +56,11 @@
5656
- [IntoIterator for arrays](rust-2021/IntoIterator-for-arrays.md)
5757
- [Disjoint capture in closures](rust-2021/disjoint-capture-in-closures.md)
5858
- [Panic macro consistency](rust-2021/panic-macro-consistency.md)
59-
- [Reserving syntax](rust-2021/reserving-syntax.md)
59+
- [Reserved syntax](rust-2021/reserved-syntax.md)
60+
- [Raw lifetimes](rust-2021/raw-lifetimes.md)
6061
- [Warnings promoted to errors](rust-2021/warnings-promoted-to-error.md)
6162
- [Or patterns in macro-rules](rust-2021/or-patterns-macro-rules.md)
63+
- [C-string literals](rust-2021/c-string-literals.md)
6264
-->
6365

6466
- [Rust 2021](rust-2021/index.md)
@@ -68,5 +70,77 @@
6870
- [クロージャはフィールドごとにキャプチャする](rust-2021/disjoint-capture-in-closures.md)
6971
- [panic マクロの一貫性](rust-2021/panic-macro-consistency.md)
7072
- [構文の予約](rust-2021/reserving-syntax.md)
73+
- [Raw lifetimes](rust-2021/raw-lifetimes.md)
7174
- [警告からエラーへの格上げ](rust-2021/warnings-promoted-to-error.md)
7275
- [マクロ規則における OR パターン](rust-2021/or-patterns-macro-rules.md)
76+
- [C-string literals](rust-2021/c-string-literals.md)
77+
78+
## Rust 2024
79+
80+
<!--
81+
- [Rust 2024](rust-2024/index.md)
82+
- [Language](rust-2024/language.md)
83+
- [RPIT lifetime capture rules](rust-2024/rpit-lifetime-capture.md)
84+
- [`if let` temporary scope](rust-2024/temporary-if-let-scope.md)
85+
- [Tail expression temporary scope](rust-2024/temporary-tail-expr-scope.md)
86+
- [Match ergonomics reservations](rust-2024/match-ergonomics.md)
87+
- [Unsafe `extern` blocks](rust-2024/unsafe-extern.md)
88+
- [Unsafe attributes](rust-2024/unsafe-attributes.md)
89+
- [`unsafe_op_in_unsafe_fn` warning](rust-2024/unsafe-op-in-unsafe-fn.md)
90+
- [Disallow references to `static mut`](rust-2024/static-mut-references.md)
91+
- [Never type fallback change](rust-2024/never-type-fallback.md)
92+
- [Macro fragment specifiers](rust-2024/macro-fragment-specifiers.md)
93+
- [Missing macro fragment specifiers](rust-2024/missing-macro-fragment-specifiers.md)
94+
- [`gen` keyword](rust-2024/gen-keyword.md)
95+
- [Reserved syntax](rust-2024/reserved-syntax.md)
96+
- [Standard library](rust-2024/standard-library.md)
97+
- [Changes to the prelude](rust-2024/prelude.md)
98+
- [Add `IntoIterator` for `Box<[T]>`](rust-2024/intoiterator-box-slice.md)
99+
- [Newly unsafe functions](rust-2024/newly-unsafe-functions.md)
100+
- [Cargo](rust-2024/cargo.md)
101+
- [Cargo: Rust-version aware resolver](rust-2024/cargo-resolver.md)
102+
- [Cargo: Table and key name consistency](rust-2024/cargo-table-key-names.md)
103+
- [Cargo: Reject unused inherited default-features](rust-2024/cargo-inherited-default-features.md)
104+
- [Rustdoc](rust-2024/rustdoc.md)
105+
- [Rustdoc combined tests](rust-2024/rustdoc-doctests.md)
106+
- [Rustdoc nested `include!` change](rust-2024/rustdoc-nested-includes.md)
107+
- [Rustfmt](rust-2024/rustfmt.md)
108+
- [Rustfmt: Style edition](rust-2024/rustfmt-style-edition.md)
109+
- [Rustfmt: Formatting fixes](rust-2024/rustfmt-formatting-fixes.md)
110+
- [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md)
111+
- [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md)
112+
- [Rustfmt: Version sorting](rust-2024/rustfmt-version-sorting.md)
113+
-->
114+
115+
- [Rust 2024](rust-2024/index.md)
116+
- [言語](rust-2024/language.md)
117+
- [RPIT lifetime capture rules](rust-2024/rpit-lifetime-capture.md)
118+
- [`if let` temporary scope](rust-2024/temporary-if-let-scope.md)
119+
- [Tail expression temporary scope](rust-2024/temporary-tail-expr-scope.md)
120+
- [Match ergonomics reservations](rust-2024/match-ergonomics.md)
121+
- [Unsafe `extern` blocks](rust-2024/unsafe-extern.md)
122+
- [Unsafe attributes](rust-2024/unsafe-attributes.md)
123+
- [`unsafe_op_in_unsafe_fn` warning](rust-2024/unsafe-op-in-unsafe-fn.md)
124+
- [Disallow references to `static mut`](rust-2024/static-mut-references.md)
125+
- [Never type fallback change](rust-2024/never-type-fallback.md)
126+
- [Macro fragment specifiers](rust-2024/macro-fragment-specifiers.md)
127+
- [Missing macro fragment specifiers](rust-2024/missing-macro-fragment-specifiers.md)
128+
- [`gen` keyword](rust-2024/gen-keyword.md)
129+
- [Reserved syntax](rust-2024/reserved-syntax.md)
130+
- [標準ライブラリ](rust-2024/standard-library.md)
131+
- [Changes to the prelude](rust-2024/prelude.md)
132+
- [Add `IntoIterator` for `Box<[T]>`](rust-2024/intoiterator-box-slice.md)
133+
- [Newly unsafe functions](rust-2024/newly-unsafe-functions.md)
134+
- [Cargo](rust-2024/cargo.md)
135+
- [Cargo: Rust-version aware resolver](rust-2024/cargo-resolver.md)
136+
- [Cargo: Table and key name consistency](rust-2024/cargo-table-key-names.md)
137+
- [Cargo: Reject unused inherited default-features](rust-2024/cargo-inherited-default-features.md)
138+
- [Rustdoc](rust-2024/rustdoc.md)
139+
- [Rustdoc combined tests](rust-2024/rustdoc-doctests.md)
140+
- [Rustdoc nested `include!` change](rust-2024/rustdoc-nested-includes.md)
141+
- [Rustfmt](rust-2024/rustfmt.md)
142+
- [Rustfmt: Style edition](rust-2024/rustfmt-style-edition.md)
143+
- [Rustfmt: Formatting fixes](rust-2024/rustfmt-formatting-fixes.md)
144+
- [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md)
145+
- [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md)
146+
- [Rustfmt: Version sorting](rust-2024/rustfmt-version-sorting.md)

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
> **Rust Edition Guide は現在 Rust 2024 のアップデート作業に向けて翻訳作業中です。本ページは英語版をコピーしていますが、一部のリンクが動作しないなどの問題が発生する場合があります。問題が発生した場合は、[原文(英語版)](https://doc.rust-lang.org/nightly/edition-guide/introduction.html)をご参照ください。**
2+
3+
# C-string literals
4+
5+
## Summary
6+
7+
- Literals of the form `c"foo"` or `cr"foo"` represent a string of type [`&core::ffi::CStr`][CStr].
8+
9+
[CStr]: ../../core/ffi/struct.CStr.html
10+
11+
## Details
12+
13+
Starting with Rust 1.77, C-strings can be written using C-string literal syntax with the `c` or `cr` prefix.
14+
15+
Previously, it was challenging to properly produce a valid string literal that could interoperate with C APIs which terminate with a NUL byte.
16+
The [`cstr`] crate was a popular solution, but that required compiling a proc-macro which was quite expensive.
17+
Now, C-strings can be written directly using literal syntax notation, which will generate a value of type [`&core::ffi::CStr`][CStr] which is automatically terminated with a NUL byte.
18+
19+
```rust,edition2021
20+
# use core::ffi::CStr;
21+
22+
assert_eq!(c"hello", CStr::from_bytes_with_nul(b"hello\0").unwrap());
23+
assert_eq!(
24+
c"byte escapes \xff work",
25+
CStr::from_bytes_with_nul(b"byte escapes \xff work\0").unwrap()
26+
);
27+
assert_eq!(
28+
c"unicode escapes \u{00E6} work",
29+
CStr::from_bytes_with_nul(b"unicode escapes \xc3\xa6 work\0").unwrap()
30+
);
31+
assert_eq!(
32+
c"unicode characters αβγ encoded as UTF-8",
33+
CStr::from_bytes_with_nul(
34+
b"unicode characters \xce\xb1\xce\xb2\xce\xb3 encoded as UTF-8\0"
35+
)
36+
.unwrap()
37+
);
38+
assert_eq!(
39+
c"strings can continue \
40+
on multiple lines",
41+
CStr::from_bytes_with_nul(b"strings can continue on multiple lines\0").unwrap()
42+
);
43+
```
44+
45+
C-strings do not allow interior NUL bytes (such as with a `\0` escape).
46+
47+
Similar to regular strings, C-strings also support "raw" syntax with the `cr` prefix.
48+
These raw C-strings do not process backslash escapes which can make it easier to write strings that contain backslashes.
49+
Double-quotes can be included by surrounding the quotes with the `#` character.
50+
Multiple `#` characters can be used to avoid ambiguity with internal `"#` sequences.
51+
52+
```rust,edition2021
53+
assert_eq!(cr"foo", c"foo");
54+
// Number signs can be used to embed interior double quotes.
55+
assert_eq!(cr#""foo""#, c"\"foo\"");
56+
// This requires two #.
57+
assert_eq!(cr##""foo"#"##, c"\"foo\"#");
58+
// Escapes are not processed.
59+
assert_eq!(cr"C:\foo", c"C:\\foo");
60+
```
61+
62+
See [The Reference] for more details.
63+
64+
[`cstr`]: https://crates.io/crates/cstr
65+
[The Reference]: ../../reference/tokens.html#c-string-and-raw-c-string-literals
66+
67+
## Migration
68+
69+
Migration is only necessary for macros which may have been assuming a sequence of tokens that looks similar to `c"…"` or `cr"…"`, which previous to the 2021 edition would tokenize as two separate tokens, but in 2021 appears as a single token.
70+
71+
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.
72+
See that chapter for more detail.
73+
74+
[syntax reservation]: reserved-syntax.md

src/rust-2021/raw-lifetimes.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
> **Rust Edition Guide は現在 Rust 2024 のアップデート作業に向けて翻訳作業中です。本ページは英語版をコピーしていますが、一部のリンクが動作しないなどの問題が発生する場合があります。問題が発生した場合は、[原文(英語版)](https://doc.rust-lang.org/nightly/edition-guide/introduction.html)をご参照ください。**
2+
3+
# Raw lifetimes
4+
5+
## Summary
6+
7+
- `'r#ident_or_keyword` is now allowed as a lifetime, which allows using keywords such as `'r#fn`.
8+
9+
## Details
10+
11+
Raw lifetimes are introduced in the 2021 edition to support the ability to migrate to newer editions that introduce new keywords. This is analogous to [raw identifiers] which provide the same functionality for identifiers. For example, the 2024 edition introduced the `gen` keyword. Since lifetimes cannot be keywords, this would cause code that use a lifetime `'gen` to fail to compile. Raw lifetimes allow the migration lint to modify those lifetimes to `'r#gen` which do allow keywords.
12+
13+
In editions prior to 2021, raw lifetimes are parsed as separate tokens. For example `'r#foo` is parsed as three tokens: `'r`, `#`, and `foo`.
14+
15+
[raw identifiers]: ../../reference/identifiers.html#raw-identifiers
16+
17+
## Migration
18+
19+
As a part of the 2021 edition a migration lint, [`rust_2021_prefixes_incompatible_syntax`], has been added in order to aid in automatic migration of Rust 2018 codebases to Rust 2021.
20+
21+
In order to migrate your code to be Rust 2021 Edition compatible, run:
22+
23+
```sh
24+
cargo fix --edition
25+
```
26+
27+
Should you want or need to manually migrate your code, migration is fairly straight-forward.
28+
29+
Let's say you have a macro that is defined like so:
30+
31+
```rust
32+
macro_rules! my_macro {
33+
($a:tt $b:tt $c:tt) => {};
34+
}
35+
```
36+
37+
In Rust 2015 and 2018 it's legal for this macro to be called like so with no space between the tokens:
38+
39+
```rust,ignore
40+
my_macro!('r#foo);
41+
```
42+
43+
In the 2021 edition, this is now parsed as a single token. In order to call this macro, you must add a space before the identifier like so:
44+
45+
```rust,ignore
46+
my_macro!('r# foo);
47+
```
48+
49+
[`rust_2021_prefixes_incompatible_syntax`]: ../../rustc/lints/listing/allowed-by-default.html#rust-2021-prefixes-incompatible-syntax
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
> **Rust Edition Guide は現在 Rust 2024 のアップデート作業に向けて翻訳作業中です。本ページは英語版をコピーしていますが、一部のリンクが動作しないなどの問題が発生する場合があります。問題が発生した場合は、[原文(英語版)](https://doc.rust-lang.org/nightly/edition-guide/introduction.html)をご参照ください。**
2+
3+
# Cargo: Reject unused inherited default-features
4+
5+
## Summary
6+
7+
- `default-features = false` is no longer allowed in an inherited workspace dependency if the workspace dependency specifies `default-features = true` (or does not specify `default-features`).
8+
9+
## Details
10+
11+
[Workspace inheritance] allows you to specify dependencies in one place (the workspace), and then to refer to those workspace dependencies from within a package.
12+
There was an inadvertent interaction with how `default-features` is specified that is no longer allowed in the 2024 Edition.
13+
14+
Unless the workspace specifies `default-features = false`, it is no longer allowed to specify `default-features = false` in an inherited package dependency.
15+
For example, with a workspace that specifies:
16+
17+
```toml
18+
[workspace.dependencies]
19+
regex = "1.10.4"
20+
```
21+
22+
The following is now an error:
23+
24+
```toml
25+
[package]
26+
name = "foo"
27+
version = "1.0.0"
28+
edition = "2024"
29+
30+
[dependencies]
31+
regex = { workspace = true, default-features = false } # ERROR
32+
```
33+
34+
The reason for this change is to avoid confusion when specifying `default-features = false` when the default feature is already enabled, since it has no effect.
35+
36+
If you want the flexibility of deciding whether or not a dependency enables the default-features of a dependency, be sure to set `default-features = false` in the workspace definition.
37+
Just beware that if you build multiple workspace members at the same time, the features will be unified so that if one member sets `default-features = true` (which is the default if not explicitly set), the default-features will be enabled for all members using that dependency.
38+
39+
## Migration
40+
41+
When using `cargo fix --edition`, Cargo will automatically update your `Cargo.toml` file to remove `default-features = false` in this situation.
42+
43+
If you would prefer to update your `Cargo.toml` manually, check for any warnings when running a build and remove the corresponding entries.
44+
Previous editions should display something like:
45+
46+
```text
47+
warning: /home/project/Cargo.toml: `default-features` is ignored for regex,
48+
since `default-features` was not specified for `workspace.dependencies.regex`,
49+
this could become a hard error in the future
50+
```
51+
52+
[workspace inheritance]: ../../cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace

src/rust-2024/cargo-resolver.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
> **Rust Edition Guide は現在 Rust 2024 のアップデート作業に向けて翻訳作業中です。本ページは英語版をコピーしていますが、一部のリンクが動作しないなどの問題が発生する場合があります。問題が発生した場合は、[原文(英語版)](https://doc.rust-lang.org/nightly/edition-guide/introduction.html)をご参照ください。**
2+
3+
# Cargo: Rust-version aware resolver
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.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
> **Rust Edition Guide は現在 Rust 2024 のアップデート作業に向けて翻訳作業中です。本ページは英語版をコピーしていますが、一部のリンクが動作しないなどの問題が発生する場合があります。問題が発生した場合は、[原文(英語版)](https://doc.rust-lang.org/nightly/edition-guide/introduction.html)をご参照ください。**
2+
3+
# Cargo: Table and key name consistency
4+
5+
## Summary
6+
7+
- Several table and key names in `Cargo.toml` have been removed where there were previously two ways to specify the same thing.
8+
- Removed `[project]`; use `[package]` instead.
9+
- Removed `default_features`; use `default-features` instead.
10+
- Removed `crate_type`; use `crate-type` instead.
11+
- Removed `proc_macro`; use `proc-macro` instead.
12+
- Removed `dev_dependencies`; use `dev-dependencies` instead.
13+
- Removed `build_dependencies`; use `build-dependencies` instead.
14+
15+
## Details
16+
17+
Several table and keys names are no longer allowed in the 2024 Edition.
18+
There were two ways to specify these tables or keys, and this helps ensure there is only one way to specify them.
19+
20+
Some were due to a change in decisions over time, and some were inadvertent implementation artifacts.
21+
In order to avoid confusion, and to enforce a single style for specifying these tables and keys, only one variant is now allowed.
22+
23+
For example:
24+
25+
```toml
26+
[dev_dependencies]
27+
rand = { version = "0.8.5", default_features = false }
28+
```
29+
30+
Should be changed to:
31+
32+
```toml
33+
[dev-dependencies]
34+
rand = { version = "0.8.5", default-features = false }
35+
```
36+
37+
Notice that the underscores were changed to dashes for `dev_dependencies` and `default_features`.
38+
39+
## Migration
40+
41+
When using `cargo fix --edition`, Cargo will automatically update your `Cargo.toml` file to use the preferred table and key names.
42+
43+
If you would prefer to update your `Cargo.toml` manually, be sure to go through the list above and make sure only the new forms are used.

src/rust-2024/cargo.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Cargo
2+
3+
<!--
4+
The following chapters detail changes to Cargo in the 2024 Edition.
5+
-->
6+
7+
以降の節では、2024 エディションでの Cargo へのアップデートについて詳説します。

0 commit comments

Comments
 (0)