Skip to content

Unclear error message on async closure #100755

Closed
@adhesivee

Description

@adhesivee

Trying to setup async closures and it took awhile to figure out what was happening.

It is when types are defined as Box<dyn Fn() -> (dyn Future<Output = ()>)>
More can be seen here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7eab934ef04fb7171121c4e4180f7f4d

The current output is:

12 | async fn message_unboxed(value: UnboxedAsync) {
   |                          ----- `value` has type `Box<dyn Fn() -> (dyn Future<Output = ()> + 'static)>`
13 |     // call expression requires function
14 |     value().await;
   |     ^^^^^--
   |     |
   |     call expression requires function

Above was apparently caused by lack of Pin<Box<_>> on the future. Once added it works fine (also on playground link)

Would be nice if the error was directing me to the return value of the closure.

Metadata

Metadata

Labels

A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions