From 91c9cb5f68319a14e0a667c4ec36193d977d44a9 Mon Sep 17 00:00:00 2001 From: dyskinmel Date: Mon, 10 Feb 2025 10:21:26 -0600 Subject: [PATCH 1/6] =?UTF-8?q?=E7=BF=BB=E8=A8=B3=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rust-2024/intoiterator-box-slice.md | 145 ++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/rust-2024/intoiterator-box-slice.md diff --git a/src/rust-2024/intoiterator-box-slice.md b/src/rust-2024/intoiterator-box-slice.md new file mode 100644 index 0000000..6c1d690 --- /dev/null +++ b/src/rust-2024/intoiterator-box-slice.md @@ -0,0 +1,145 @@ + + +# Box<[T]> に対する IntoIterator の追加 + + + +## 概要 + + + +- ボックス化されたスライスは、*すべて* のエディションで [`IntoIterator`] を実装します。 +- 2024年以前のエディションでは、メソッド呼び出し構文(例: `boxed_slice.into_iter()` )で [`IntoIterator::into_iter`] への呼び出しが *隠蔽* されるため、これまでどおり `boxed_slice.into_iter()` は `(&(*boxed_slice)).into_iter()` として解釈されます。 +- Rust 2024 では、`boxed_slice.into_iter()` の意味が `IntoIterator::into_iter` を呼び出すものに変わります。 + +[`IntoIterator`]: ../../std/iter/trait.IntoIterator.html +[`IntoIterator::into_iter`]: ../../std/iter/trait.IntoIterator.html#tymethod.into_iter + + + +## 詳細 + +Rust 1.80 以前は、ボックス化されたスライスに対して IntoIterator が実装されていませんでした。以前のバージョンでは、ボックス化されたスライスに対して .into_iter() を呼び出すと、メソッド呼び出しが自動的に Box<[T]> から &[T] への参照外しを行い、&T の参照を返すイテレータが生成されました。たとえば、以下のコードは以前のエディションで動作していました: + + + +```rust +// Example of behavior in previous editions. +// 以前のエディションでの動作例 +let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); +// Note: .into_iter() was required in versions older than 1.80 +// 注意:1.80以前のバージョンでは .into_iter() の呼び出しが必要でした +for x in my_boxed_slice.into_iter() { + // x is of type &u32 in editions prior to 2024 + // Rust 2024以前のエディションでは、x の型は &u32 です +} +``` + + + +Rust 1.80 以降、ボックス化されたスライスに対して IntoIterator の実装が追加されました。これにより、スライスの要素を参照ではなく値としてイテレートできるようになります: + +```rust +// NEW as of 1.80, all editions +// 1.80以降、すべてのエディションでの新しい動作 +let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); +for x in my_boxed_slice { // notice no need for calling .into_iter() + // .into_iter() の呼び出しは不要です + // x is of type u32 + // x の型は u32 です +} +``` + + + +この例は、すべてのエディションで許可されています。というのも、以前は for ループが .into_iter() のように自動的に参照外しを行わなかったため、そもそもエラーになっていたからです。 + + + +しかし、本来であれば、これは破壊的変更となる可能性があります。なぜなら、これまで .into_iter() を明示的に呼び出していたコードの動作が、参照を返すイテレータから値を返すイテレータへと変わってしまうからです。この問題を解決するために、ボックス化されたスライスの .into_iter() の動作はエディションによって異なります。2024年以前のエディションでは、これまでどおり参照を返すイテレータを生成します。Rust 2024 以降では、値を返すイテレータを生成します。 + +```rust,edition2024 +// Example of changed behavior in Edition 2024 +// Edition 2024 での動作変更の例 +let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); +// Example of old code that still manually calls .into_iter() +// 以前のコードで .into_iter() を明示的に呼び出していた場合 +for x in my_boxed_slice.into_iter() { + // x is now type u32 in Edition 2024 + // Edition 2024 では、x の型は u32 になります +} +``` + + + +## 移行 + + + +boxed_slice_into_iter リントは、ボックス化されたスライスに対する .into_iter() の呼び出しを .iter() に自動で置き換え、従来どおり参照を返すように修正します。このリントは rust-2024-compatibility リントグループの一部であり、cargo fix --edition を実行すると自動的に適用されます。Rust 2024 エディションに対応するために、次のコマンドを実行してください。 + +```sh +cargo fix --edition +``` + + + +例えば、以下のコードは: + +```rust +fn main() { + let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); + for x in my_boxed_slice.into_iter() { + // x is of type &u32 + // x の型は &u32 + } +} +``` + + + +次のように修正されます: + +```rust +fn main() { + let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); + for x in my_boxed_slice.iter() { + // x is of type &u32 + // x の型は &u32 + } +} +``` + + + +boxed_slice_into_iter リントはすべてのエディションでデフォルトで警告を出す設定になっているため、手動でリントを無効化していなければ、移行前にすでに警告が表示されるはずです。 + +[`boxed_slice_into_iter`]: ../../rustc/lints/listing/warn-by-default.html#boxed-slice-into-iter From c9dd8fe36de986a708c188a0cf5be6eec3164635 Mon Sep 17 00:00:00 2001 From: dyskinmel Date: Wed, 12 Feb 2025 10:28:55 -0600 Subject: [PATCH 2/6] =?UTF-8?q?=E7=BF=BB=E8=A8=B3=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rust-2024/intoiterator-box-slice.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rust-2024/intoiterator-box-slice.md b/src/rust-2024/intoiterator-box-slice.md index 6c1d690..0a7b9b2 100644 --- a/src/rust-2024/intoiterator-box-slice.md +++ b/src/rust-2024/intoiterator-box-slice.md @@ -16,7 +16,7 @@ - `boxed_slice.into_iter()` changes meaning to call [`IntoIterator::into_iter`] in Rust 2024. --> -- ボックス化されたスライスは、*すべて* のエディションで [`IntoIterator`] を実装します。 +- ボックス化されたスライスは、*すべての* エディションで [`IntoIterator`] を実装します。 - 2024年以前のエディションでは、メソッド呼び出し構文(例: `boxed_slice.into_iter()` )で [`IntoIterator::into_iter`] への呼び出しが *隠蔽* されるため、これまでどおり `boxed_slice.into_iter()` は `(&(*boxed_slice)).into_iter()` として解釈されます。 - Rust 2024 では、`boxed_slice.into_iter()` の意味が `IntoIterator::into_iter` を呼び出すものに変わります。 @@ -29,12 +29,12 @@ ## 詳細 -Rust 1.80 以前は、ボックス化されたスライスに対して IntoIterator が実装されていませんでした。以前のバージョンでは、ボックス化されたスライスに対して .into_iter() を呼び出すと、メソッド呼び出しが自動的に Box<[T]> から &[T] への参照外しを行い、&T の参照を返すイテレータが生成されました。たとえば、以下のコードは以前のエディションで動作していました: - +Rust 1.80 以前は、ボックス化されたスライスに対して `IntoIterator` が実装されていませんでした。以前のバージョンでは、ボックス化されたスライスに対して `.into_iter()` を呼び出すと、メソッド呼び出しが自動的に `Box<[T]>` から `&[T]` への参照外しを行い、`&T` の参照を返すイテレータが生成されました。たとえば、以下のコードは以前のエディションで動作していました: + ```rust // Example of behavior in previous editions. // 以前のエディションでの動作例 @@ -51,7 +51,7 @@ for x in my_boxed_slice.into_iter() { In Rust 1.80, implementations of `IntoIterator` were added for boxed slices. This allows iterating over elements of the slice by-value instead of by-reference: --> -Rust 1.80 以降、ボックス化されたスライスに対して IntoIterator の実装が追加されました。これにより、スライスの要素を参照ではなく値としてイテレートできるようになります: +Rust 1.80 では、ボックス化されたスライスに対して `IntoIterator` の実装が追加されました。これにより、スライスの要素を参照ではなく値としてイテレートできるようになります: ```rust // NEW as of 1.80, all editions @@ -68,13 +68,13 @@ for x in my_boxed_slice { // notice no need for calling .into_iter() This example is allowed on all editions because previously this was an error since `for` loops do not automatically dereference like the `.into_iter()` method call does. --> -この例は、すべてのエディションで許可されています。というのも、以前は for ループが .into_iter() のように自動的に参照外しを行わなかったため、そもそもエラーになっていたからです。 +この例は、すべてのエディションで許可されています。というのも、以前は `for` ループが `.into_iter()` のように自動的に参照外しを行わなかったため、そもそもエラーになっていたからです。 -しかし、本来であれば、これは破壊的変更となる可能性があります。なぜなら、これまで .into_iter() を明示的に呼び出していたコードの動作が、参照を返すイテレータから値を返すイテレータへと変わってしまうからです。この問題を解決するために、ボックス化されたスライスの .into_iter() の動作はエディションによって異なります。2024年以前のエディションでは、これまでどおり参照を返すイテレータを生成します。Rust 2024 以降では、値を返すイテレータを生成します。 +しかし、本来であれば、これは破壊的変更となる可能性があります。なぜなら、これまで `.into_iter()` を明示的に呼び出していたコードの動作が、参照を返すイテレータから値を返すイテレータへと変わってしまうからです。この問題を解決するために、ボックス化されたスライスの `.into_iter()` の動作はエディションによって異なります。2024年以前のエディションでは、これまでどおり参照を返すイテレータを生成します。Rust 2024 以降では、値を返すイテレータを生成します。 ```rust,edition2024 // Example of changed behavior in Edition 2024 @@ -98,7 +98,7 @@ for x in my_boxed_slice.into_iter() { The [`boxed_slice_into_iter`] lint will automatically modify any calls to `.into_iter()` on boxed slices to call `.iter()` instead to retain the old behavior of yielding references. This lint is part of the `rust-2024-compatibility` lint group, which will automatically be applied when running `cargo fix --edition`. To migrate your code to be Rust 2024 Edition compatible, run: --> -boxed_slice_into_iter リントは、ボックス化されたスライスに対する .into_iter() の呼び出しを .iter() に自動で置き換え、従来どおり参照を返すように修正します。このリントは rust-2024-compatibility リントグループの一部であり、cargo fix --edition を実行すると自動的に適用されます。Rust 2024 エディションに対応するために、次のコマンドを実行してください。 +[`boxed_slice_into_iter`] リントは、ボックス化されたスライスに対する `.into_iter()` の呼び出しを `.iter()` に自動で置き換え、従来どおり参照を返すように修正します。このリントは `rust-2024-compatibility` リントグループの一部であり、`cargo fix --edition` を実行すると自動的に適用されます。Rust 2024 エディションに対応するために、次のコマンドを実行してください。 ```sh cargo fix --edition @@ -140,6 +140,6 @@ fn main() { The [`boxed_slice_into_iter`] lint is defaulted to warn on all editions, so unless you have manually silenced the lint, you should already see it before you migrate. --> -boxed_slice_into_iter リントはすべてのエディションでデフォルトで警告を出す設定になっているため、手動でリントを無効化していなければ、移行前にすでに警告が表示されるはずです。 +[`boxed_slice_into_iter`] リントはすべてのエディションでデフォルトで警告を出す設定になっているため、手動でリントを無効化していなければ、移行前にすでに警告が表示されるはずです。 [`boxed_slice_into_iter`]: ../../rustc/lints/listing/warn-by-default.html#boxed-slice-into-iter From b0174f848690adf09049e67a80460ec9f72a14a8 Mon Sep 17 00:00:00 2001 From: dyskinmel Date: Wed, 12 Feb 2025 10:29:12 -0600 Subject: [PATCH 3/6] =?UTF-8?q?Summary=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SUMMARY.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 5c12430..a351fd6 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -70,3 +70,73 @@ - [構文の予約](rust-2021/reserving-syntax.md) - [警告からエラーへの格上げ](rust-2021/warnings-promoted-to-error.md) - [マクロ規則における OR パターン](rust-2021/or-patterns-macro-rules.md) + +## Rust 2024 + + + +- [Rust 2024](rust-2024/index.md) + - [Language](rust-2024/language.md) + - [RPIT lifetime capture rules](rust-2024/rpit-lifetime-capture.md) + - [`if let` temporary scope](rust-2024/temporary-if-let-scope.md) + - [Tail expression temporary scope](rust-2024/temporary-tail-expr-scope.md) + - [Match ergonomics reservations](rust-2024/match-ergonomics.md) + - [Unsafe `extern` blocks](rust-2024/unsafe-extern.md) + - [Unsafe attributes](rust-2024/unsafe-attributes.md) + - [`unsafe_op_in_unsafe_fn` warning](rust-2024/unsafe-op-in-unsafe-fn.md) + - [Disallow references to `static mut`](rust-2024/static-mut-references.md) + - [Never type fallback change](rust-2024/never-type-fallback.md) + - [Macro fragment specifiers](rust-2024/macro-fragment-specifiers.md) + - [Missing macro fragment specifiers](rust-2024/missing-macro-fragment-specifiers.md) + - [`gen` keyword](rust-2024/gen-keyword.md) + - [Reserved syntax](rust-2024/reserved-syntax.md) + - [Standard library](rust-2024/standard-library.md) + - [Changes to the prelude](rust-2024/prelude.md) + - [Box<[T]> に対する IntoIterator の追加](rust-2024/intoiterator-box-slice.md) + - [Newly unsafe functions](rust-2024/newly-unsafe-functions.md) + - [Cargo](rust-2024/cargo.md) + - [Cargo: Rust-version aware resolver](rust-2024/cargo-resolver.md) + - [Cargo: Table and key name consistency](rust-2024/cargo-table-key-names.md) + - [Cargo: Reject unused inherited default-features](rust-2024/cargo-inherited-default-features.md) + - [Rustdoc](rust-2024/rustdoc.md) + - [Rustdoc combined tests](rust-2024/rustdoc-doctests.md) + - [Rustdoc nested `include!` change](rust-2024/rustdoc-nested-includes.md) + - [Rustfmt](rust-2024/rustfmt.md) + - [Rustfmt: Style edition](rust-2024/rustfmt-style-edition.md) + - [Rustfmt: Formatting fixes](rust-2024/rustfmt-formatting-fixes.md) + - [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md) + - [Rustfmt: Raw identifier sorting](rust-2024/rustfmt-raw-identifier-sorting.md) + - [Rustfmt: Version sorting](rust-2024/rustfmt-version-sorting.md) \ No newline at end of file From e22f17bbd2b925d2ac7290f6a4485c28d05959cb Mon Sep 17 00:00:00 2001 From: dyskinmel Date: Thu, 20 Feb 2025 16:33:55 -0600 Subject: [PATCH 4/6] =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=AF=E3=82=92?= =?UTF-8?q?=E7=9B=B8=E5=AF=BE=E3=83=91=E3=82=B9=E3=81=8B=E3=82=89=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rust-2024/intoiterator-box-slice.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rust-2024/intoiterator-box-slice.md b/src/rust-2024/intoiterator-box-slice.md index cf57b44..b904c39 100644 --- a/src/rust-2024/intoiterator-box-slice.md +++ b/src/rust-2024/intoiterator-box-slice.md @@ -20,8 +20,8 @@ - 2024年以前のエディションでは、メソッド呼び出し構文(例: `boxed_slice.into_iter()` )で [`IntoIterator::into_iter`] への呼び出しが *隠蔽* されるため、これまでどおり `boxed_slice.into_iter()` は `(&(*boxed_slice)).into_iter()` として解釈されます。 - Rust 2024 では、`boxed_slice.into_iter()` の意味が `IntoIterator::into_iter` を呼び出すものに変わります。 -[`IntoIterator`]: ../../std/iter/trait.IntoIterator.html -[`IntoIterator::into_iter`]: ../../std/iter/trait.IntoIterator.html#tymethod.into_iter +[`IntoIterator`]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html +[`IntoIterator::into_iter`]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html#tymethod.into_iter # Box<[T]> に対する IntoIterator の追加 - ## 概要 - -- ボックス化されたスライスは、*すべての* エディションで [`IntoIterator`] を実装します。 -- 2024年以前のエディションでは、メソッド呼び出し構文(例: `boxed_slice.into_iter()` )で [`IntoIterator::into_iter`] への呼び出しが *隠蔽* されるため、これまでどおり `boxed_slice.into_iter()` は `(&(*boxed_slice)).into_iter()` として解釈されます。 +- ボックス化されたスライスは、*すべての*エディションで [`IntoIterator`] を実装します。 +- 2024年以前のエディションでは、メソッド呼び出し構文(例: `boxed_slice.into_iter()` )で [`IntoIterator::into_iter`] への呼び出しが*隠蔽*されるため、これまでどおり `boxed_slice.into_iter()` は `(&(*boxed_slice)).into_iter()` として解釈されます。 - Rust 2024 では、`boxed_slice.into_iter()` の意味が `IntoIterator::into_iter` を呼び出すものに変わります。 + + [`IntoIterator`]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html [`IntoIterator::into_iter`]: https://doc.rust-lang.org/std/iter/trait.IntoIterator.html#tymethod.into_iter - ## 詳細 - Rust 1.80 以前は、ボックス化されたスライスに対して `IntoIterator` が実装されていませんでした。以前のバージョンでは、ボックス化されたスライスに対して `.into_iter()` を呼び出すと、メソッド呼び出しが自動的に `Box<[T]>` から `&[T]` への参照外しを行い、`&T` の参照を返すイテレータが生成されました。たとえば、以下のコードは以前のエディションで動作していました: + + +```rust +// 以前のエディションでの動作例 +let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); +// 注意:1.80以前のバージョンでは .into_iter() の呼び出しが必要です +for x in my_boxed_slice.into_iter() { // Rust 2024以前のエディションでは、x の型は &u32 です } ``` - Rust 1.80 では、ボックス化されたスライスに対して `IntoIterator` の実装が追加されました。これにより、スライスの要素を参照ではなく値としてイテレートできるようになります: + + +```rust +// 1.80以降、すべてのエディションでの新しい動作 +let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); +for x in my_boxed_slice { // .into_iter() の呼び出しは不要です // x の型は u32 です } ``` - この例は、すべてのエディションで許可されています。というのも、以前は `for` ループが `.into_iter()` のように自動的に参照外しを行わなかったため、そもそもエラーになっていたからです。 - しかし、本来であれば、これは破壊的変更となる可能性があります。なぜなら、これまで `.into_iter()` を明示的に呼び出していたコードの動作が、参照を返すイテレータから値を返すイテレータへと変わってしまうからです。この問題を解決するために、ボックス化されたスライスの `.into_iter()` の動作はエディションによって異なります。2024年以前のエディションでは、これまでどおり参照を返すイテレータを生成します。Rust 2024 以降では、値を返すイテレータを生成します。 + + +```rust,edition2024 +// Edition 2024 での動作変更の例 +let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); +// Example of old code that still manually calls .into_iter() +// .into_iter() を明示的に呼び出していた古いコードの例 +for x in my_boxed_slice.into_iter() { // Edition 2024 では、x の型は u32 になります } ``` - ## 移行 - [`boxed_slice_into_iter`] リントは、ボックス化されたスライスに対する `.into_iter()` の呼び出しを `.iter()` に自動で置き換え、従来どおり参照を返すように修正します。このリントは `rust-2024-compatibility` リントグループの一部であり、`cargo fix --edition` を実行すると自動的に適用されます。Rust 2024 エディションに対応するために、次のコマンドを実行してください。 @@ -106,43 +134,65 @@ cargo fix --edition ``` 例えば、以下のコードは: + + +```rust +fn main() { + let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); + for x in my_boxed_slice.into_iter() { // x の型は &u32 } } ``` - 次のように修正されます: - + + +```rust +fn main() { + let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); + for x in my_boxed_slice.iter() { // x の型は &u32 } } ``` - [`boxed_slice_into_iter`] リントはすべてのエディションでデフォルトで警告を出す設定になっているため、手動でリントを無効化していなければ、移行前にすでに警告が表示されるはずです。 + [`boxed_slice_into_iter`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#boxed-slice-into-iter From 1b21b84237152b41ae46991a29b642ab173bf38a Mon Sep 17 00:00:00 2001 From: dyskinmel Date: Wed, 26 Feb 2025 11:30:07 -0600 Subject: [PATCH 6/6] =?UTF-8?q?=E7=BF=BB=E8=A8=B3=E3=81=AE=E4=B8=80?= =?UTF-8?q?=E9=83=A8=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rust-2024/intoiterator-box-slice.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rust-2024/intoiterator-box-slice.md b/src/rust-2024/intoiterator-box-slice.md index 57028f4..1525cc4 100644 --- a/src/rust-2024/intoiterator-box-slice.md +++ b/src/rust-2024/intoiterator-box-slice.md @@ -56,7 +56,7 @@ for x in my_boxed_slice.into_iter() { let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); // 注意:1.80以前のバージョンでは .into_iter() の呼び出しが必要です for x in my_boxed_slice.into_iter() { - // Rust 2024以前のエディションでは、x の型は &u32 です + // Rust 2024 以前のエディションでは、x の型は &u32 です } ``` @@ -79,7 +79,7 @@ for x in my_boxed_slice { // notice no need for calling .into_iter() ```rust // 1.80以降、すべてのエディションでの新しい動作 let my_boxed_slice: Box<[u32]> = vec![1, 2, 3].into_boxed_slice(); -for x in my_boxed_slice { // .into_iter() の呼び出しは不要です +for x in my_boxed_slice { // .into_iter() の呼び出しは不要になっています // x の型は u32 です } ```