Skip to content

Commit 70ef3c1

Browse files
committed
Add details of the compiler errors that occur when trying to use get_mut().
1 parent e224ead commit 70ef3c1

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/04_pinning/01_chapter.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,27 @@ pub fn main() {
480480
# }
481481
```
482482

483-
The type system prevents us from moving the data.
483+
The type system prevents us from moving the data, as follows:
484+
485+
```
486+
error[E0277]: `PhantomPinned` cannot be unpinned
487+
--> src\test.rs:56:30
488+
|
489+
56 | std::mem::swap(test1.get_mut(), test2.get_mut());
490+
| ^^^^^^^ within `test1::Test`, the trait `Unpin` is not implemented for `PhantomPinned`
491+
|
492+
= note: consider using `Box::pin`
493+
note: required because it appears within the type `test1::Test`
494+
--> src\test.rs:7:8
495+
|
496+
7 | struct Test {
497+
| ^^^^
498+
note: required by a bound in `std::pin::Pin::<&'a mut T>::get_mut`
499+
--> <...>rustlib/src/rust\library\core\src\pin.rs:748:12
500+
|
501+
748 | T: Unpin,
502+
| ^^^^^ required by this bound in `std::pin::Pin::<&'a mut T>::get_mut`
503+
```
484504

485505
> It's important to note that stack pinning will always rely on guarantees
486506
> you give when writing `unsafe`. While we know that the _pointee_ of `&'a mut T`

0 commit comments

Comments
 (0)