Skip to content

Slightly incorrect help message with mismatched typs in async code #66910

Closed
@jfrimmel

Description

@jfrimmel

The following works, since foo and bar return (), so the expression is simply returned:

fn foo() {}
fn bar() {
    foo()
}

The "equivalent" code in the async context yields a compiler error:

async fn foo() {}
async fn bar() {
    foo()
}
error[E0308]: mismatched types
  --> src/main.rs:62:5
   |
62 |     foo()
   |     ^^^^^- help: try adding a semicolon: `;`
   |     |
   |     expected (), found opaque type
   |
   = note: expected type `()`
              found type `impl core::future::future::Future`

The help message would be correct for non-async-code with mismatched types, but in the async case a .await should be suggested.

Technically the current help message is correct, but leads to another warning (that can be even overlooked):

warning: unused implementer of `core::future::future::Future` that must be used
  --> src/main.rs:62:5
   |
62 |     foo();
   |     ^^^^^^
   |
   = note: `#[warn(unused_must_use)]` on by default
   = note: futures do nothing unless you `.await` or poll them

So you have to do a second compile iteration.

I'd suggest to spawn a help message like that:

error[E0308]: mismatched types
  --> src/main.rs:62:5
   |
62 |     foo()
   |     ^^^^^- help: try to await the future: `.await`
   |     |
   |     expected (), found opaque type
   |
   = note: expected type `()`
              found type `impl core::future::future::Future`

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-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