Closed
Description
When BoxFuture
is expected and we supply Pin::new(async { /* .. */ })
, Box::new(async { /* .. */ })
or Pin::new(Box::new(async { /* .. */ }))
we should lead the user in the right direction instead of what we do now:
error[E0277]: the trait bound `dyn std::future::Future<Output = i32> + std::marker::Send: std::marker::Unpin` is not satisfied
--> file5.rs:10:5
|
10 | Pin::new(async { 42 })
| ^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `dyn std::future::Future<Output = i32> + std::marker::Send`
|
= note: required by `std::pin::Pin::<P>::new`
error[E0308]: mismatched types
--> file5.rs:10:5
|
9 | fn foo() -> BoxFuture<'static, i32> {
| ----------------------- expected `std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = i32> + std::marker::Send + 'static)>>` because of return type
10 | Box::new(async { 42 })
| ^^^^^^^^^^^^^^^^^^^^^^
| |
| expected struct `std::pin::Pin`, found struct `std::boxed::Box`
| help: you need to pin and box this expression: `Box::pin(Box::new(async { 42 }))`
|
= note: expected struct `std::pin::Pin<std::boxed::Box<(dyn std::future::Future<Output = i32> + std::marker::Send + 'static)>>`
found struct `std::boxed::Box<impl std::future::Future>`
error[E0277]: the trait bound `dyn std::future::Future<Output = i32> + std::marker::Send: std::marker::Unpin` is not satisfied
--> file5.rs:10:5
|
10 | Pin::new(Box::new(async { 42 }))
| ^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `dyn std::future::Future<Output = i32> + std::marker::Send`
|
= note: required by `std::pin::Pin::<P>::new`
For the second case we could suggest Box::into_pin
once #62370 stabilizes. The other two cases can be handled with a rustc_on_unimplemented
note.
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Async-await issues that have been triaged during a working group meeting.Category: An issue proposing an enhancement or a PR with one.Relevant to the compiler team, which will review and decide on the PR/issue.