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` フラグを渡しているでしょうが、これを変える必要はありません。 -<!-- -> One small note here: `cargo fix` will not currently automate this change. We may -> have it do this for you in the future. ---> - -> 一つ注意ですが、`cargo fix` は今の所この変更を自動では行いません。 -> 将来、自動で変更がなされるようになるかもしれません。 - <!-- #### An exception --> @@ -192,7 +184,7 @@ Some examples of needing to explicitly import sysroot crates are: 例えば、以下のような場合には明示的に sysroot のクレートをインポートする必要があります: <!-- -* [`std`]: Usually this is not neccesary, because `std` is automatically +* [`std`]: Usually this is not necessary, because `std` is automatically imported unless the crate is marked with [`#![no_std]`][no_std]. * [`core`]: Usually this is not necessary, because `core` is automatically imported, unless the crate is marked with [`#![no_core]`][no_core]. For @@ -395,6 +387,16 @@ mod submodule { } ``` +<!-- +If you have a local module or item with the same name as an external crate, a +path beginning with that name will be taken to refer to the local module or +item. To explicitly refer to the external crate, use the `::name` form. +--> + +プロジェクト内に外部クレートと同名のローカルなモジュールやアイテムがある場合、 +その名前から始まるパスは後者として解釈されます。 +明示的に外部クレートを参照したい場合、パスの先頭を `::name` とすればよいです。 + <!-- ### No more `mod.rs` --> @@ -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` から始まるパスも使用できます。 <!-- Code that looked like this: @@ -617,15 +619,3 @@ additional complexity to multi-module projects. --> これにより、コードを他の場所に移動することが簡単になり、マルチモジュールなプロジェクトがより複雑になるのを防止できます。 - -<!-- -If a path is ambiguous, such as if you have an external crate and a local -module or item with the same name, you'll get an error, and you'll need to -either rename one of the conflicting names or explicitly disambiguate the path. -To explicitly disambiguate a path, use `::name` for an external crate name, or -`self::name` for a local module or item. ---> - -もし、例えば外部モジュールとローカルのモジュールが同名であるなど、パスが曖昧な場合は、エラーになります。 -その場合、他と衝突している名前のうち一方を変更するか、明示的にパスの曖昧性をなくす必要があります。 -パスの曖昧性をなくすには、`::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 <!-- diff --git a/src/rust-2021/disjoint-capture-in-closures.md b/src/rust-2021/disjoint-capture-in-closures.md index 437ecc2..1130c42 100644 --- a/src/rust-2021/disjoint-capture-in-closures.md +++ b/src/rust-2021/disjoint-capture-in-closures.md @@ -83,10 +83,10 @@ As a part of the 2021 edition a migration lint, `rust_2021_incompatible_closure_ Rust 2018 のコードベースから Rust 2021 への自動移行の支援のため、2021 エディションには、移行用のリント`rust_2021_incompatible_closure_captures` が追加されています。 <!-- -In order to have `rustfix` migrate your code to be Rust 2021 Edition compatible, run: +In order to migrate your code to be Rust 2021 Edition compatible, run: --> -`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`]: if all captured values are [`Clone`]. +- [`Clone`]: if all captured values are `Clone`. - [Auto traits] like [`Send`], [`Sync`], and [`UnwindSafe`]: if all captured values implement the given trait. --> -- [`Clone`]: キャプチャされた値がすべて [`Clone`] を実装していた場合。 +- [`Clone`]: キャプチャされた値がすべて `Clone` を実装していた場合。 - [`Send`], [`Sync`], [`UnwindSafe`] などの[自動トレイト]: キャプチャされた値がすべてそのトレイトを実装していた場合。 <!-- @@ -282,7 +282,7 @@ Closures automatically implement the following traits based on what values they [`clone`]: https://doc.rust-lang.org/std/clone/trait.Clone.html [`send`]: https://doc.rust-lang.org/std/marker/trait.Send.html [`sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html -[`unwindsafe`]: https://doc.rust-lang.org/std/marker/trait.UnwindSafe.html +[`unwindsafe`]: https://doc.rust-lang.org/std/panic/trait.UnwindSafe.html --> [自動トレイト]: 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` が追加されています。 <!-- -In order to have `rustfix` migrate your code to be Rust 2021 Edition compatible, run: +In order to migrate your code to be Rust 2021 Edition compatible, run: --> -`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 場合によっては、今までと同じ関数が呼び出されるように、あなたのコードを様々な方法で書き換えることもあります。 <!-- -If you'd like to migrate your code manually or better understand what `rustfix` is doing, below we've outlined the situations where a migration is needed along with a counter example of when it's not needed. +If you'd like to migrate your code manually or better understand what `cargo fix` is doing, below we've outlined the situations where a migration is needed along with a counter example of when it's not needed. --> -コードの移行を手作業で行いたい方や `rustfix` が何を行うかをより詳しく理解したい方のために、どのような状況で移行が必要なのか、逆にどうであれば不要なのを以下に例示していきます。 +コードの移行を手作業で行いたい方や `cargo fix` が何を行うかをより詳しく理解したい方のために、どのような状況で移行が必要なのか、逆にどうであれば不要なのを以下に例示していきます。 <!-- ### Migration needed diff --git a/src/rust-2021/reserving-syntax.md b/src/rust-2021/reserved-syntax.md similarity index 79% rename from src/rust-2021/reserving-syntax.md rename to src/rust-2021/reserved-syntax.md index e1e5727..7eb7421 100644 --- a/src/rust-2021/reserving-syntax.md +++ b/src/rust-2021/reserved-syntax.md @@ -1,5 +1,5 @@ <!-- -# Reserving syntax +# Reserved syntax --> # 構文の予約 @@ -11,8 +11,7 @@ ## 概要 <!-- -- `any_identifier#`, `any_identifier"..."`, and `any_identifier'...'` are now reserved - syntax, and no longer tokenize. +- `any_identifier#`, `any_identifier"..."`, `any_identifier'...'`, and `'any_identifier#` are now reserved syntax, and no longer tokenize. - This is mostly relevant to macros. E.g. `quote!{ #a#b }` is no longer accepted. - It doesn't treat keywords specially, so e.g. `match"..." {}` is no longer accepted. - Insert whitespace between the identifier and the subsequent `#`, `"`, or `'` @@ -20,7 +19,7 @@ - Edition migrations will help you insert whitespace in such cases. --> -- `shikibetsushi#`, `shikibetsushi"..."`, `shikibetsushi'...'` の3つの構文が新たに予約され、トークン分割されなくなりました。 +- `shikibetsushi#`, `shikibetsushi"..."`, `shikibetsushi'...'`, `'any_identifier#` の4つの構文が新たに予約され、トークン分割されなくなりました。 - 主に影響を受けるのはマクロです。例えば、`quote!{ #a#b }` と書くことはできなくなりました。 - キーワードが特別扱いされることもないので、例えば `match"..." {}` と書くこともできなくなりました。 - 識別子と後続の `#`, `"`, `'` の間に空白文字を挿入することで、エラーを回避できます。 @@ -34,16 +33,16 @@ <!-- To make space for new syntax in the future, -we've decided to reserve syntax for prefixed identifiers and literals: -`prefix#identifier`, `prefix"string"`, `prefix'c'`, and `prefix#123`, +we've decided to reserve syntax for prefixed identifiers, literals, and lifetimes: +`prefix#identifier`, `prefix"string"`, `prefix'c'`, `prefix#123`, and `'prefix#`, where `prefix` can be any identifier. (Except those prefixes that already have a meaning, such as `b'...'` (byte -strings) and `r"..."` (raw strings).) +chars) and `r"..."` (raw strings).) --> -私達は、将来新しい構文を導入する余地を残すため、接頭辞付きの識別子とリテラルの構文を予約することにしました。 -予約されたのは、任意の識別子 `prefix` を用いて `prefix#identifier`, `prefix"string"`, `prefix'c'`, `prefix#123` のいずれかの形で書かれるものです。 -(ただし、`b'...'`(バイト文字列)や`r"..."`(生文字列)のように、すでに意味が割り当てられているものを除きます。) +私達は、将来新しい構文を導入する余地を残すため、接頭辞付きの識別子・リテラル・ライフタイムの構文を予約することにしました。 +予約されたのは、任意の識別子 `prefix` を用いて `prefix#identifier`, `prefix"string"`, `prefix'c'`, `prefix#123`, `'prefix#` のいずれかの形で書かれるものです。 +(ただし、`b'...'`(バイト文字)や`r"..."`(生文字列)のように、すでに意味が割り当てられているものを除きます。) <!-- This provides syntax we can expand into in the future without requiring an @@ -112,12 +111,6 @@ committed to any of them yet): - `s""` で `String` リテラルを表す。 -<!-- -- `c""` or `z""` for null-terminated C strings. ---> - -- `c""` か `z""` で、ヌル終端のC言語の文字列を表す。 - [10]: https://github.com/rust-lang/rfcs/pull/3101 @@ -128,16 +121,16 @@ committed to any of them yet): ## 移行 <!-- -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. +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. --> -Rust 2018 のコードベースから Rust 2021 への自動移行の支援のため、2021 エディションには、移行用のリント`rust_2021_prefixes_incompatible_syntax` が追加されています。 +Rust 2018 のコードベースから Rust 2021 への自動移行の支援のため、2021 エディションには、移行用のリント[`rust_2021_prefixes_incompatible_syntax`] が追加されています。 <!-- -In order to have `rustfix` migrate your code to be Rust 2021 Edition compatible, run: +In order to migrate your code to be Rust 2021 Edition compatible, run: --> -`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`]: ../../rustc/lints/listing/allowed-by-default.html#rust-2021-prefixes-incompatible-syntax +--> + +[`rust_2021_prefixes_incompatible_syntax`]: https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#rust-2021-prefixes-incompatible-syntax