-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
fn foo() -> BoxFuture<'static, i32> {
async {
42
}
}
gives
error[E0308]: mismatched types
--> src/lib.rs:5:5
|
4 | fn foo() -> BoxFuture<'static, i32> {
| ----------------------- expected `std::pin::Pin<std::boxed::Box<(dyn core::future::future::Future<Output = i32> + std::marker::Send + 'static)>>` because of return type
5 | / async {
6 | | 42
7 | | }
| |_____^ expected struct `std::pin::Pin`, found opaque type
|
= note: expected type `std::pin::Pin<std::boxed::Box<(dyn core::future::future::Future<Output = i32> + std::marker::Send + 'static)>>`
found type `impl core::future::future::Future`
The expected struct std::pin::Pin
in particular is confusing. This can be a pretty intimidating error message for someone new to async/await, when all they forgot was .boxed()
.
I'm not sure if we can fix this without stabilizing BoxFuture
so we can sprinkle some magic compiler dust on its error messages. Maybe there's something we can do, though. Maybe some intelligent use of type aliases in our error messages?
cc @JakeEhrlich
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
Done
Milestone
Relationships
Development
Select code repository
Activity
estebank commentedon Jan 14, 2020
This can be handled without needing to stabilize the struct. It should act the same way that the primitive type cast suggestions do.
nikomatsakis commentedon Feb 11, 2020
Some observations:
BoxFuture
struct, it's a type-aliasboxed()
but that is a method defined only in the futures crate, which feels a bit awkward to me; I'd rather it were part of libstdBox::pin(async { .. })
as well (playground)tmandry commentedon Feb 11, 2020
marking as OnDeck, since BoxFuture gets used quite often
estebank commentedon Feb 12, 2020
I have a PR that suggests the right code for this:
But if first you try
Box::new
:or
Pin::new
:we will send you in a wild goose chase:
BoxFuture
and usingasync {}
, suggestBox::pin
#69082estebank commentedon Feb 12, 2020
Filed #69083 for the uncovered cases.
Rollup merge of rust-lang#69082 - estebank:boxfuture-box-pin, r=tmandry