Also modify `DispatchFromDyn` for `Pin`

This commit is contained in:
Alice Ryhl 2024-05-11 11:16:59 +02:00
parent 7f4e36beed
commit 1eec5b3351
1 changed files with 8 additions and 2 deletions

View File

@ -646,8 +646,7 @@ introduce a `StableDeref` trait:
unsafe trait StableDeref: Deref { }
```
Then we make it so that you can only coerce pinned pointers when they implement
`StableDeref`. We can do that by modifying its implementation of
[`CoerceUnsized`] to this:
`StableDeref`. We can do that by modifying its trait implementations to this:
```rs
impl<T, U> CoerceUnsized<Pin<U>> for Pin<T>
where
@ -655,6 +654,13 @@ where
T: StableDeref,
U: StableDeref,
{}
impl<T, U> DispatchFromDyn<Pin<U>> for Pin<T>
where
T: CoerceUnsized<U>,
T: StableDeref,
U: StableDeref,
{}
```
This way, the user must implement the unsafe trait before they can coerce
pinned versions of the pointer. Since the trait is unsafe, it is not our fault