From 1ba06fe61c39c1379bd768060c21040b62ff3f0b Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Thu, 21 Aug 2025 18:18:20 -0600 Subject: [PATCH] Update playground error messages --- .../edition-2/posts/10-heap-allocation/index.ja.md | 1 + blog/content/edition-2/posts/10-heap-allocation/index.md | 1 + .../edition-2/posts/10-heap-allocation/index.zh-CN.md | 1 + blog/content/edition-2/posts/12-async-await/index.es.md | 8 ++++---- blog/content/edition-2/posts/12-async-await/index.ja.md | 8 ++++---- blog/content/edition-2/posts/12-async-await/index.md | 8 ++++---- .../content/edition-2/posts/12-async-await/index.zh-CN.md | 8 ++++---- .../content/edition-2/posts/12-async-await/index.zh-TW.md | 8 ++++---- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/blog/content/edition-2/posts/10-heap-allocation/index.ja.md b/blog/content/edition-2/posts/10-heap-allocation/index.ja.md index c5fb9e13..53ba6320 100644 --- a/blog/content/edition-2/posts/10-heap-allocation/index.ja.md +++ b/blog/content/edition-2/posts/10-heap-allocation/index.ja.md @@ -167,6 +167,7 @@ error[E0597]: `z[_]` does not live long enough 2 | let x = { | - borrow later stored here 3 | let z = Box::new([1,2,3]); + | - binding `z` declared here 4 | &z[1] | ^^^^^ borrowed value does not live long enough 5 | }; // z goes out of scope and `deallocate` is called diff --git a/blog/content/edition-2/posts/10-heap-allocation/index.md b/blog/content/edition-2/posts/10-heap-allocation/index.md index 22e8d234..a1ab5dd5 100644 --- a/blog/content/edition-2/posts/10-heap-allocation/index.md +++ b/blog/content/edition-2/posts/10-heap-allocation/index.md @@ -164,6 +164,7 @@ error[E0597]: `z[_]` does not live long enough 2 | let x = { | - borrow later stored here 3 | let z = Box::new([1,2,3]); + | - binding `z` declared here 4 | &z[1] | ^^^^^ borrowed value does not live long enough 5 | }; // z goes out of scope and `deallocate` is called diff --git a/blog/content/edition-2/posts/10-heap-allocation/index.zh-CN.md b/blog/content/edition-2/posts/10-heap-allocation/index.zh-CN.md index fc04d973..b15eba41 100644 --- a/blog/content/edition-2/posts/10-heap-allocation/index.zh-CN.md +++ b/blog/content/edition-2/posts/10-heap-allocation/index.zh-CN.md @@ -165,6 +165,7 @@ error[E0597]: `z[_]` does not live long enough 2 | let x = { | - borrow later stored here 3 | let z = Box::new([1,2,3]); + | - binding `z` declared here 4 | &z[1] | ^^^^^ borrowed value does not live long enough 5 | }; // z goes out of scope and `deallocate` is called diff --git a/blog/content/edition-2/posts/12-async-await/index.es.md b/blog/content/edition-2/posts/12-async-await/index.es.md index 7a95f75c..9c8ddf6c 100644 --- a/blog/content/edition-2/posts/12-async-await/index.es.md +++ b/blog/content/edition-2/posts/12-async-await/index.es.md @@ -632,21 +632,21 @@ Además de cambiar `Box::new` a `Box::pin`, también necesitamos añadir el nuev Cuando [intentamos ejecutar nuestro ejemplo ajustado](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=961b0db194bbe851ff4d0ed08d3bd98a) ahora, vemos que ya no funciona: ``` -error[E0594]: cannot assign to data in a dereference of `std::pin::Pin>` +error[E0594]: cannot assign to data in dereference of `Pin>` --> src/main.rs:10:5 | 10 | heap_value.self_ptr = ptr; | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` -error[E0596]: cannot borrow data in a dereference of `std::pin::Pin>` as mutable +error[E0596]: cannot borrow data in dereference of `Pin>` as mutable --> src/main.rs:16:36 | 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { | ^^^^^^^^^^^^^^^^ cannot borrow as mutable | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` ``` Ambos errores ocurren porque el tipo `Pin>` ya no implementa el trait `DerefMut`. Esto es exactamente lo que queremos porque el trait `DerefMut` devolvería una referencia `&mut`, que queremos prevenir. Esto solo ocurre porque ambos optamos por no implementar `Unpin` y cambiamos `Box::new` a `Box::pin`. diff --git a/blog/content/edition-2/posts/12-async-await/index.ja.md b/blog/content/edition-2/posts/12-async-await/index.ja.md index c2e7d343..7aa7761a 100644 --- a/blog/content/edition-2/posts/12-async-await/index.ja.md +++ b/blog/content/edition-2/posts/12-async-await/index.ja.md @@ -640,21 +640,21 @@ let mut heap_value = Box::pin(SelfReferential { 今、[調整した例を実行してみると](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=961b0db194bbe851ff4d0ed08d3bd98a)、動作しなくなっていることがわかります: ``` -error[E0594]: cannot assign to data in a dereference of `std::pin::Pin>` +error[E0594]: cannot assign to data in dereference of `Pin>` --> src/main.rs:10:5 | 10 | heap_value.self_ptr = ptr; | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` -error[E0596]: cannot borrow data in a dereference of `std::pin::Pin>` as mutable +error[E0596]: cannot borrow data in dereference of `Pin>` as mutable --> src/main.rs:16:36 | 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { | ^^^^^^^^^^^^^^^^ cannot borrow as mutable | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` ``` どちらのエラーも、`Pin>` 型が `DerefMut` trait を実装しなくなったために発生します。これはまさに求めていた結果であり、というのも、`DerefMut` trait は `&mut` 参照を返してしまうからで、私達はこれを防ぎたかったのです。これは、`Unpin` を使用しないようにして、`Box::new` を `Box::pin` に変更したからこそ起こる現象です。 diff --git a/blog/content/edition-2/posts/12-async-await/index.md b/blog/content/edition-2/posts/12-async-await/index.md index 48f0417d..4ff78197 100644 --- a/blog/content/edition-2/posts/12-async-await/index.md +++ b/blog/content/edition-2/posts/12-async-await/index.md @@ -634,21 +634,21 @@ In addition to changing `Box::new` to `Box::pin`, we also need to add the new `_ When we [try to run our adjusted example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=961b0db194bbe851ff4d0ed08d3bd98a) now, we see that it no longer works: ``` -error[E0594]: cannot assign to data in a dereference of `std::pin::Pin>` +error[E0594]: cannot assign to data in dereference of `Pin>` --> src/main.rs:10:5 | 10 | heap_value.self_ptr = ptr; | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` -error[E0596]: cannot borrow data in a dereference of `std::pin::Pin>` as mutable +error[E0596]: cannot borrow data in dereference of `Pin>` as mutable --> src/main.rs:16:36 | 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { | ^^^^^^^^^^^^^^^^ cannot borrow as mutable | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` ``` Both errors occur because the `Pin>` type no longer implements the `DerefMut` trait. This is exactly what we wanted because the `DerefMut` trait would return a `&mut` reference, which we wanted to prevent. This only happens because we both opted-out of `Unpin` and changed `Box::new` to `Box::pin`. diff --git a/blog/content/edition-2/posts/12-async-await/index.zh-CN.md b/blog/content/edition-2/posts/12-async-await/index.zh-CN.md index e5927938..9749365b 100644 --- a/blog/content/edition-2/posts/12-async-await/index.zh-CN.md +++ b/blog/content/edition-2/posts/12-async-await/index.zh-CN.md @@ -649,21 +649,21 @@ let mut heap_value = Box::pin(SelfReferential { 当我们现在[尝试运行调整后的示例](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=961b0db194bbe851ff4d0ed08d3bd98a)时,会发现它会报错: ``` -error[E0594]: cannot assign to data in a dereference of `std::pin::Pin>` +error[E0594]: cannot assign to data in dereference of `Pin>` --> src/main.rs:10:5 | 10 | heap_value.self_ptr = ptr; | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` -error[E0596]: cannot borrow data in a dereference of `std::pin::Pin>` as mutable +error[E0596]: cannot borrow data in dereference of `Pin>` as mutable --> src/main.rs:16:36 | 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { | ^^^^^^^^^^^^^^^^ cannot borrow as mutable | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` ``` 这两个错误的发生是因为 `Pin>` 类型不再实现 `DerefMut` trait。这正是我们想要的,因为 `DerefMut` trait 会返回一个 `&mut` 引用,而这正是我们想要避免的。这种情况之所以发生,仅仅是因为我们同时选择了不实现 `Unpin` 并将 `Box::new` 改为 `Box::pin`。 diff --git a/blog/content/edition-2/posts/12-async-await/index.zh-TW.md b/blog/content/edition-2/posts/12-async-await/index.zh-TW.md index 5b78d13f..e50491ce 100644 --- a/blog/content/edition-2/posts/12-async-await/index.zh-TW.md +++ b/blog/content/edition-2/posts/12-async-await/index.zh-TW.md @@ -749,21 +749,21 @@ let mut heap_value = Box::pin(SelfReferential { 當我們 [嘗試運行我們調整後的例子](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=961b0db194bbe851ff4d0ed08d3bd98a) 時,我們看到它不再工作: ``` -error[E0594]: cannot assign to data in a dereference of `std::pin::Pin>` +error[E0594]: cannot assign to data in dereference of `Pin>` --> src/main.rs:10:5 | 10 | heap_value.self_ptr = ptr; | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` -error[E0596]: cannot borrow data in a dereference of `std::pin::Pin>` as mutable +error[E0596]: cannot borrow data in dereference of `Pin>` as mutable --> src/main.rs:16:36 | 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { | ^^^^^^^^^^^^^^^^ cannot borrow as mutable | - = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin>` + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin>` ``` 由於 `Pin>` 類型不再實現 `DerefMut` 特型,所以這兩個錯誤都發生了。