Closed
Description
Given the following code:
use futures::executor::block_on;
async fn return_number() -> usize {
return 1;
}
async fn return_call_async() -> usize {
// return return_number().await;
return return_number();
}
fn main() {
let s = block_on(return_call_async());
print!("{}", &s);
}
The current (pretty decent) output is:
error[E0308]: mismatched types
--> src/main.rs:8:12
|
3 | async fn return_number() -> usize {
| ----- the `Output` of this `async fn`'s found opaque type
...
8 | return return_number();
| ^^^^^^^^^^^^^^^ expected `usize`, found opaque type
|
= note: expected type `usize`
found opaque type `impl futures::Future`
help: consider `await`ing on the `Future`
|
8 | return return_number().await;
| ^^^^^^
error: aborting due to previous error
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
nikomatsakis commentedon Apr 13, 2021
This comes from @jlkiri's comment here
nikomatsakis commentedon Apr 13, 2021
I think the output should be more aggressive. For example:
estebank commentedon Apr 13, 2021
Another alternative would be to explicitly state what the
fn
s desugared type is:[-]improve error for missing [/-][+]improve error for missing await[/+]SNCPlay42 commentedon Apr 13, 2021
Related, if not a duplicate, to #80658
SNCPlay42 commentedon Apr 13, 2021
The note has changed on nightly/beta, from the PR linked to that isssue:
nikomatsakis commentedon Apr 13, 2021
I agree this is something of a duplicate. I can move the conversation over there.
async fn
is involved in a type mismatch is unclear #80658