diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 6d03c91..ed08723 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -69,7 +69,7 @@ - [配列に対する IntoIterator](rust-2021/IntoIterator-for-arrays.md) - [クロージャはフィールドごとにキャプチャする](rust-2021/disjoint-capture-in-closures.md) - [panic マクロの一貫性](rust-2021/panic-macro-consistency.md) - - [構文の予約](rust-2021/reserving-syntax.md) + - [構文の予約](rust-2021/reserved-syntax.md) - [Raw lifetimes](rust-2021/raw-lifetimes.md) - [警告からエラーへの格上げ](rust-2021/warnings-promoted-to-error.md) - [マクロ規則における OR パターン](rust-2021/or-patterns-macro-rules.md) diff --git a/src/rust-2018/path-changes.md b/src/rust-2018/path-changes.md index 58fc37d..de3f08f 100644 --- a/src/rust-2018/path-changes.md +++ b/src/rust-2018/path-changes.md @@ -149,14 +149,6 @@ keep doing what you were doing there as well. 今や、プロジェクトに新しくクレートを追加したかったら、`Cargo.toml` に追記して、それで終わりです。 Cargo を使用していない場合は、`rustc` に外部クレートの場所を `--extern` フラグを渡しているでしょうが、これを変える必要はありません。 - - -> 一つ注意ですが、`cargo fix` は今の所この変更を自動では行いません。 -> 将来、自動で変更がなされるようになるかもしれません。 - @@ -192,7 +184,7 @@ Some examples of needing to explicitly import sysroot crates are: 例えば、以下のような場合には明示的に sysroot のクレートをインポートする必要があります: + +プロジェクト内に外部クレートと同名のローカルなモジュールやアイテムがある場合、 +その名前から始まるパスは後者として解釈されます。 +明示的に外部クレートを参照したい場合、パスの先頭を `::name` とすればよいです。 + @@ -498,11 +500,11 @@ Rust 2015 では、`use` 宣言におけるパスは他の場所と異なった In Rust 2018, paths in `use` declarations and in other code work the same way, both in the top-level module and in any submodule. You can use a relative path from the current scope, a path starting from an external crate name, or a path -starting with `crate`, `super`, or `self`. +starting with `::`, `crate`, `super`, or `self`. --> Rust 2018 では、トップレベルモジュールかサブモジュールかに関わらず、`use` 宣言でのパスと他のプログラム中のパスは同じように使用できます。 -現在のスコープからの相対パスも、外部クレート名から始まるパスも、`crate`, `super`, `self` から始まるパスも使用できます。 +現在のスコープからの相対パスも、外部クレート名から始まるパスも、`::`, `crate`, `super`, `self` から始まるパスも使用できます。 これにより、コードを他の場所に移動することが簡単になり、マルチモジュールなプロジェクトがより複雑になるのを防止できます。 - - - -もし、例えば外部モジュールとローカルのモジュールが同名であるなど、パスが曖昧な場合は、エラーになります。 -その場合、他と衝突している名前のうち一方を変更するか、明示的にパスの曖昧性をなくす必要があります。 -パスの曖昧性をなくすには、`::name` と書いて外部クレート名であることを明示するか、`self::name` と書いてローカルのモジュールやアイテムであることを明示すればよいです。 diff --git a/src/rust-2021/default-cargo-resolver.md b/src/rust-2021/default-cargo-resolver.md index 1d0c86f..2b03a86 100644 --- a/src/rust-2021/default-cargo-resolver.md +++ b/src/rust-2021/default-cargo-resolver.md @@ -63,14 +63,14 @@ See [the announcement of Rust 1.51][5] for details. [4]: ../../cargo/reference/resolver.html#feature-resolver-version-2 [5]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver [workspace]: ../../cargo/reference/workspaces.html -[virtual workspace]: ../../cargo/reference/workspaces.html#virtual-manifest +[virtual workspace]: ../../cargo/reference/workspaces.html#virtual-workspace [`resolver` field]: ../../cargo/reference/resolver.html#resolver-versions --> [4]: https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2 [5]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver [ワークスペース]: https://doc.rust-lang.org/cargo/reference/workspaces.html -[仮想ワークスペース]: https://doc.rust-lang.org/cargo/reference/workspaces.html#virtual-manifest +[仮想ワークスペース]: https://doc.rust-lang.org/cargo/reference/workspaces.html#virtual-workspace [`resolver` フィールド]: https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions -`rustfix` でコードを Rust 2021 エディションに適合させるためには、次のように実行します。 +コードを Rust 2021 エディションに適合させるためには、次のように実行します。 ```sh cargo fix --edition @@ -270,11 +270,11 @@ Closures automatically implement the following traits based on what values they 何がキャプチャされているかによって、クロージャには自動的に以下のトレイトが実装されます: -- [`Clone`]: キャプチャされた値がすべて [`Clone`] を実装していた場合。 +- [`Clone`]: キャプチャされた値がすべて `Clone` を実装していた場合。 - [`Send`], [`Sync`], [`UnwindSafe`] などの[自動トレイト]: キャプチャされた値がすべてそのトレイトを実装していた場合。 [自動トレイト]: https://doc.rust-lang.org/nightly/reference/special-types-and-traits.html#auto-traits diff --git a/src/rust-2021/prelude.md b/src/rust-2021/prelude.md index 71053d2..479ac08 100644 --- a/src/rust-2021/prelude.md +++ b/src/rust-2021/prelude.md @@ -94,10 +94,10 @@ As a part of the 2021 edition a migration lint, `rust_2021_prelude_collisions`, Rust 2018 コードベースから Rust 2021 への自動移行の支援のため、2021 エディションには、移行用のリント`rust_2021_prelude_collisions` が追加されています。 -`rustfix` でコードを Rust 2021 エディションに適合させるためには、次のように実行します。 +コードを Rust 2021 エディションに適合させるためには、次のように実行します。 ```sh cargo fix --edition @@ -111,10 +111,10 @@ The lint detects cases where functions or methods are called that have the same 場合によっては、今までと同じ関数が呼び出されるように、あなたのコードを様々な方法で書き換えることもあります。 -コードの移行を手作業で行いたい方や `rustfix` が何を行うかをより詳しく理解したい方のために、どのような状況で移行が必要なのか、逆にどうであれば不要なのを以下に例示していきます。 +コードの移行を手作業で行いたい方や `cargo fix` が何を行うかをより詳しく理解したい方のために、どのような状況で移行が必要なのか、逆にどうであれば不要なのを以下に例示していきます。 # 構文の予約 @@ -11,8 +11,7 @@ ## 概要 -- `shikibetsushi#`, `shikibetsushi"..."`, `shikibetsushi'...'` の3つの構文が新たに予約され、トークン分割されなくなりました。 +- `shikibetsushi#`, `shikibetsushi"..."`, `shikibetsushi'...'`, `'any_identifier#` の4つの構文が新たに予約され、トークン分割されなくなりました。 - 主に影響を受けるのはマクロです。例えば、`quote!{ #a#b }` と書くことはできなくなりました。 - キーワードが特別扱いされることもないので、例えば `match"..." {}` と書くこともできなくなりました。 - 識別子と後続の `#`, `"`, `'` の間に空白文字を挿入することで、エラーを回避できます。 @@ -34,16 +33,16 @@ -私達は、将来新しい構文を導入する余地を残すため、接頭辞付きの識別子とリテラルの構文を予約することにしました。 -予約されたのは、任意の識別子 `prefix` を用いて `prefix#identifier`, `prefix"string"`, `prefix'c'`, `prefix#123` のいずれかの形で書かれるものです。 -(ただし、`b'...'`(バイト文字列)や`r"..."`(生文字列)のように、すでに意味が割り当てられているものを除きます。) +私達は、将来新しい構文を導入する余地を残すため、接頭辞付きの識別子・リテラル・ライフタイムの構文を予約することにしました。 +予約されたのは、任意の識別子 `prefix` を用いて `prefix#identifier`, `prefix"string"`, `prefix'c'`, `prefix#123`, `'prefix#` のいずれかの形で書かれるものです。 +(ただし、`b'...'`(バイト文字)や`r"..."`(生文字列)のように、すでに意味が割り当てられているものを除きます。) - -- `c""` か `z""` で、ヌル終端のC言語の文字列を表す。 - [10]: https://github.com/rust-lang/rfcs/pull/3101 @@ -128,16 +121,16 @@ committed to any of them yet): ## 移行 -Rust 2018 のコードベースから Rust 2021 への自動移行の支援のため、2021 エディションには、移行用のリント`rust_2021_prefixes_incompatible_syntax` が追加されています。 +Rust 2018 のコードベースから Rust 2021 への自動移行の支援のため、2021 エディションには、移行用のリント[`rust_2021_prefixes_incompatible_syntax`] が追加されています。 -`rustfix` でコードを Rust 2021 エディションに適合させるためには、次のように実行します。 +コードを Rust 2021 エディションに適合させるためには、次のように実行します。 ```sh cargo fix --edition @@ -180,3 +173,9 @@ Rust 2021 では `z` という接頭辞は許されないので、このマク ```rust,ignore my_macro!(z "hey"); ``` + + + +[`rust_2021_prefixes_incompatible_syntax`]: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#rust-2021-prefixes-incompatible-syntax