Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear error message on async closure #100755

Closed
adhesivee opened this issue Aug 19, 2022 · 3 comments · Fixed by #101359
Closed

Unclear error message on async closure #100755

adhesivee opened this issue Aug 19, 2022 · 3 comments · Fixed by #101359
Assignees
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@adhesivee
Copy link

adhesivee commented Aug 19, 2022

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.

@adhesivee adhesivee added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 19, 2022
@estebank estebank added A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Aug 22, 2022
@compiler-errors
Copy link
Member

compiler-errors commented Aug 29, 2022

This has nothing to do with async specifically -- this has to do with the fact that you can't call a Fn trait object that returns an unsized type, like dyn Future. I can make the "call expression requires function" message instead say something along those lines.

@compiler-errors compiler-errors self-assigned this Aug 29, 2022
@eholk
Copy link
Contributor

eholk commented Aug 29, 2022

Marking as triaged since @compiler-errors is working on it.

@rustbot label +AsyncAwait-Triaged

@rustbot rustbot added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Aug 29, 2022
@compiler-errors
Copy link
Member

This is blocked on #101100, some machinery in that PR which I'll use to make this suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
5 participants