-
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 lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.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
This code (playground):
fn main() {
let my_future = async || {
1
};
}
prints out
error[E0658]: async closures are unstable
--> src/main.rs:2:21
|
2 | let my_future = async || {
| ^^^^^
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
error: aborting due to previous error
This is pretty unhelpful for beginners - normally this happens when they try to use await
in a closure, which tells them they need async:
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> src/main.rs:3:9
|
2 | let my_future = || {
| -- this is not `async`
3 | 1.await
| ^^^^^^^ only allowed inside `async` functions and blocks
But when they do they get an error about async being unstable, which they have no idea how to solve. The fix is to remove the pipe symbols:
async { }
However, this requires knowledge that async blocks desugar internally into closures, which is not at all clear from the syntax. It would be better for the compiler to suggest it:
error[E0658]: async closures are unstable
--> src/main.rs:2:21
|
2 | let my_future = async || {
| ^^^^^^^^^^ help: to use an async block, remove the `||`: `async {`
|
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
L0g4n, pickfire, Kobzol, guswynn, trevyn and 1 more
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.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