Skip to content

Rust doesn't suggest adding a return type for async functions #90027

Closed
@KamilaBorowska

Description

@KamilaBorowska

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=ef06e37eae2f34c12c2143d48c9b4a0a

async fn hello() {
    Ok(())
}

The current output is:

error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
2 |     Ok(())
  |     ^^^^^^- help: consider using a semicolon here: `;`
  |     |
  |     expected `()`, found enum `Result`
  |
  = note: expected unit type `()`
                  found enum `Result<(), _>`

Ideally the output should look like:

error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
2 |     Ok(())
  |     ^^^^^^ expected `()`, found enum `Result`
  |
  = note: expected unit type `()`
                  found enum `Result<(), _>`
help: consider using a semicolon here
  |
2 |     Ok(());
  |           +
help: try adding a return type
  |
1 | async fn hello() -> Result<(), _> {
  |                  ++++++++++++++++

Rust already suggests adding a return type when the function is not async.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.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