Skip to content

Suggest making fn async if future found in return expr #159495

Description

@estebank

Code

async fn number() -> i32 {
    42
}

fn wrapped_number() -> i32 {
    number()
}

Current output

error[E0308]: mismatched types
 --> src/lib.rs:6:5
  |
5 | fn wrapped_number() -> i32 {
  |                        --- expected `i32` because of return type
6 |     number()
  |     ^^^^^^^^ expected `i32`, found future

Desired output

error[E0308]: mismatched types
 --> src/lib.rs:6:5
  |
5 | fn wrapped_number() -> i32 {
  |                        --- expected `i32` because of return type
6 |     number()
  |     ^^^^^^^^ expected `i32`, found future
help: consider making the function `async`
  |
5 | async fn wrapped_number() -> i32 {
  | +++++
help: if you make the function `async`, you can `await` on the future
6 |     number().await
  |             ++++++

Rationale and extra context

No response

Other cases

Rust Version

1.97

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.P-lowLow priorityT-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