Update playground error messages

This commit is contained in:
Thalia Archibald
2025-08-21 18:18:20 -06:00
parent bae61dd786
commit 1ba06fe61c
8 changed files with 23 additions and 20 deletions

View File

@@ -167,6 +167,7 @@ error[E0597]: `z[_]` does not live long enough
2 | let x = { 2 | let x = {
| - borrow later stored here | - borrow later stored here
3 | let z = Box::new([1,2,3]); 3 | let z = Box::new([1,2,3]);
| - binding `z` declared here
4 | &z[1] 4 | &z[1]
| ^^^^^ borrowed value does not live long enough | ^^^^^ borrowed value does not live long enough
5 | }; // z goes out of scope and `deallocate` is called 5 | }; // z goes out of scope and `deallocate` is called

View File

@@ -164,6 +164,7 @@ error[E0597]: `z[_]` does not live long enough
2 | let x = { 2 | let x = {
| - borrow later stored here | - borrow later stored here
3 | let z = Box::new([1,2,3]); 3 | let z = Box::new([1,2,3]);
| - binding `z` declared here
4 | &z[1] 4 | &z[1]
| ^^^^^ borrowed value does not live long enough | ^^^^^ borrowed value does not live long enough
5 | }; // z goes out of scope and `deallocate` is called 5 | }; // z goes out of scope and `deallocate` is called

View File

@@ -165,6 +165,7 @@ error[E0597]: `z[_]` does not live long enough
2 | let x = { 2 | let x = {
| - borrow later stored here | - borrow later stored here
3 | let z = Box::new([1,2,3]); 3 | let z = Box::new([1,2,3]);
| - binding `z` declared here
4 | &z[1] 4 | &z[1]
| ^^^^^ borrowed value does not live long enough | ^^^^^ borrowed value does not live long enough
5 | }; // z goes out of scope and `deallocate` is called 5 | }; // z goes out of scope and `deallocate` is called

View File

@@ -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: 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<std::boxed::Box<SelfReferential>>` error[E0594]: cannot assign to data in dereference of `Pin<Box<SelfReferential>>`
--> src/main.rs:10:5 --> src/main.rs:10:5
| |
10 | heap_value.self_ptr = ptr; 10 | heap_value.self_ptr = ptr;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
error[E0596]: cannot borrow data in a dereference of `std::pin::Pin<std::boxed::Box<SelfReferential>>` as mutable error[E0596]: cannot borrow data in dereference of `Pin<Box<SelfReferential>>` as mutable
--> src/main.rs:16:36 --> src/main.rs:16:36
| |
16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential {
| ^^^^^^^^^^^^^^^^ cannot borrow as mutable | ^^^^^^^^^^^^^^^^ cannot borrow as mutable
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
``` ```
Ambos errores ocurren porque el tipo `Pin<Box<SelfReferential>>` 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`. Ambos errores ocurren porque el tipo `Pin<Box<SelfReferential>>` 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`.

View File

@@ -640,21 +640,21 @@ let mut heap_value = Box::pin(SelfReferential {
今、[調整した例を実行してみると](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=961b0db194bbe851ff4d0ed08d3bd98a)、動作しなくなっていることがわかります: 今、[調整した例を実行してみると](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<std::boxed::Box<SelfReferential>>` error[E0594]: cannot assign to data in dereference of `Pin<Box<SelfReferential>>`
--> src/main.rs:10:5 --> src/main.rs:10:5
| |
10 | heap_value.self_ptr = ptr; 10 | heap_value.self_ptr = ptr;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
error[E0596]: cannot borrow data in a dereference of `std::pin::Pin<std::boxed::Box<SelfReferential>>` as mutable error[E0596]: cannot borrow data in dereference of `Pin<Box<SelfReferential>>` as mutable
--> src/main.rs:16:36 --> src/main.rs:16:36
| |
16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential {
| ^^^^^^^^^^^^^^^^ cannot borrow as mutable | ^^^^^^^^^^^^^^^^ cannot borrow as mutable
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
``` ```
どちらのエラーも、`Pin<Box<SelfReferential>>` 型が `DerefMut` trait を実装しなくなったために発生します。これはまさに求めていた結果であり、というのも、`DerefMut` trait は `&mut` 参照を返してしまうからで、私達はこれを防ぎたかったのです。これは、`Unpin` を使用しないようにして、`Box::new``Box::pin` に変更したからこそ起こる現象です。 どちらのエラーも、`Pin<Box<SelfReferential>>` 型が `DerefMut` trait を実装しなくなったために発生します。これはまさに求めていた結果であり、というのも、`DerefMut` trait は `&mut` 参照を返してしまうからで、私達はこれを防ぎたかったのです。これは、`Unpin` を使用しないようにして、`Box::new``Box::pin` に変更したからこそ起こる現象です。

View File

@@ -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: 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<std::boxed::Box<SelfReferential>>` error[E0594]: cannot assign to data in dereference of `Pin<Box<SelfReferential>>`
--> src/main.rs:10:5 --> src/main.rs:10:5
| |
10 | heap_value.self_ptr = ptr; 10 | heap_value.self_ptr = ptr;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
error[E0596]: cannot borrow data in a dereference of `std::pin::Pin<std::boxed::Box<SelfReferential>>` as mutable error[E0596]: cannot borrow data in dereference of `Pin<Box<SelfReferential>>` as mutable
--> src/main.rs:16:36 --> src/main.rs:16:36
| |
16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential {
| ^^^^^^^^^^^^^^^^ cannot borrow as mutable | ^^^^^^^^^^^^^^^^ cannot borrow as mutable
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
``` ```
Both errors occur because the `Pin<Box<SelfReferential>>` 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`. Both errors occur because the `Pin<Box<SelfReferential>>` 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`.

View File

@@ -649,21 +649,21 @@ let mut heap_value = Box::pin(SelfReferential {
当我们现在[尝试运行调整后的示例](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=961b0db194bbe851ff4d0ed08d3bd98a)时,会发现它会报错: 当我们现在[尝试运行调整后的示例](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<std::boxed::Box<SelfReferential>>` error[E0594]: cannot assign to data in dereference of `Pin<Box<SelfReferential>>`
--> src/main.rs:10:5 --> src/main.rs:10:5
| |
10 | heap_value.self_ptr = ptr; 10 | heap_value.self_ptr = ptr;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
error[E0596]: cannot borrow data in a dereference of `std::pin::Pin<std::boxed::Box<SelfReferential>>` as mutable error[E0596]: cannot borrow data in dereference of `Pin<Box<SelfReferential>>` as mutable
--> src/main.rs:16:36 --> src/main.rs:16:36
| |
16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential {
| ^^^^^^^^^^^^^^^^ cannot borrow as mutable | ^^^^^^^^^^^^^^^^ cannot borrow as mutable
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
``` ```
这两个错误的发生是因为 `Pin<Box<SelfReferential>>` 类型不再实现 `DerefMut` trait。这正是我们想要的因为 `DerefMut` trait 会返回一个 `&mut` 引用,而这正是我们想要避免的。这种情况之所以发生,仅仅是因为我们同时选择了不实现 `Unpin` 并将 `Box::new` 改为 `Box::pin` 这两个错误的发生是因为 `Pin<Box<SelfReferential>>` 类型不再实现 `DerefMut` trait。这正是我们想要的因为 `DerefMut` trait 会返回一个 `&mut` 引用,而这正是我们想要避免的。这种情况之所以发生,仅仅是因为我们同时选择了不实现 `Unpin` 并将 `Box::new` 改为 `Box::pin`

View File

@@ -749,21 +749,21 @@ let mut heap_value = Box::pin(SelfReferential {
當我們 [嘗試運行我們調整後的例子](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=961b0db194bbe851ff4d0ed08d3bd98a) 時,我們看到它不再工作: 當我們 [嘗試運行我們調整後的例子](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<std::boxed::Box<SelfReferential>>` error[E0594]: cannot assign to data in dereference of `Pin<Box<SelfReferential>>`
--> src/main.rs:10:5 --> src/main.rs:10:5
| |
10 | heap_value.self_ptr = ptr; 10 | heap_value.self_ptr = ptr;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
error[E0596]: cannot borrow data in a dereference of `std::pin::Pin<std::boxed::Box<SelfReferential>>` as mutable error[E0596]: cannot borrow data in dereference of `Pin<Box<SelfReferential>>` as mutable
--> src/main.rs:16:36 --> src/main.rs:16:36
| |
16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential { 16 | let stack_value = mem::replace(&mut *heap_value, SelfReferential {
| ^^^^^^^^^^^^^^^^ cannot borrow as mutable | ^^^^^^^^^^^^^^^^ cannot borrow as mutable
| |
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::pin::Pin<std::boxed::Box<SelfReferential>>` = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Pin<Box<SelfReferential>>`
``` ```
由於 `Pin<Box<SelfReferential>>` 類型不再實現 `DerefMut` 特型,所以這兩個錯誤都發生了。 由於 `Pin<Box<SelfReferential>>` 類型不再實現 `DerefMut` 特型,所以這兩個錯誤都發生了。