[rust-lang/rust] pin!() is unsound due to coercions
Sponsored Content
### ROOT CAUSE
The root cause of the issue is that the `pin!()` macro does not actually pin the data in memory when used with the provided `Thing` struct. The `Drop` implementation of `Thing` takes ownership of the data and moves it into `storage`, which can lead to undefined behavior if the reference is still in use. The `pin!()` macro, in this case, does not prevent the `Thing` struct from being dropped, allowing the data to be moved, which violates the pinning invariant.
### CODE FIX
To fix this issue, we need to ensure that the data is properly pinned and not dropped prematurely. One approach is to use a heap-allocated structure, such as a `Box`, to hold the data, ensuring that it remains in place. Additionally, we should modify the `Drop` implementation to not take ownership of the data if it's already been moved. Here's the corrected code:
```rust
use std::ops::{Deref, DerefMut};
use std::pin::{Pin, pin};
use std::task::{Context, Poll, Waker};
struct Thing {
data: Box