rust
async_error
ai_generated
true
the trait `Unpin` is not implemented for `impl Future<Output = T>`
ID: rust/rust-pin-unpin-error
82%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Async futures are not Unpin by default. Use Box::pin or pin! macro to handle self-referential futures.
genericWorkarounds
-
92% success Use Box::pin() to pin the future on the heap
let fut = Box::pin(async { ... }); // or for trait objects: Box<dyn Future<Output=T> + Send>Sources: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.pin
-
88% success Use tokio::pin! or std::pin::pin! macro for stack pinning
use tokio::pin; let fut = async { ... }; pin!(fut); fut.await;
Dead Ends
Common approaches that don't work:
-
Implement Unpin for the future type manually
90% fail
Self-referential futures are unsound to move; manually implementing Unpin breaks safety guarantees
Error Chain
Preceded by:
Frequently confused with: