Closed
Description
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`