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

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

Closed
KamilaBorowska opened this issue Oct 18, 2021 · 1 comment · Fixed by #107685
Closed

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

KamilaBorowska opened this issue Oct 18, 2021 · 1 comment · Fixed by #107685
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@KamilaBorowska
Copy link
Contributor

KamilaBorowska commented Oct 18, 2021

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.

@KamilaBorowska KamilaBorowska 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 Oct 18, 2021
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 19, 2021
@jieyouxu
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants