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

suggest `await` for future-related type errors #61076

Open
nikomatsakis opened this issue May 23, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@nikomatsakis
Copy link
Contributor

commented May 23, 2019

A common problem when using async-await is to forget to invoke .await. This often shows up as a type error, e.g. in a case like this (playground):

#![feature(async_await)]

async fn make_u32() -> u32 {
    22
}

fn take_u32(x: u32) {

}

async fn foo() {
    let x = make_u32();
    take_u32(x);
}

fn main() { }

currently we give a rather generic error:

error[E0308]: mismatched types
  --> src/main.rs:13:14
   |
13 |     take_u32(x);
   |              ^ expected u32, found opaque type
   |
   = note: expected type `u32`
              found type `impl std::future::Future`

it'd be nice if we could suggest adding .await somewhere.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

commented May 23, 2019

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

commented May 23, 2019

@wycats was reporting a much worse error, but I'm quite sure what he did to encounter it:

image

Probably has something to do with streams?

@estebank

This comment has been minimized.

Copy link
Contributor

commented May 23, 2019

This will be harder to do for chained expessions future.field_or_resolved_future.execute_new_future()? that should have been future.await.field_or_resolved_future.execute_new_future().await?.

@cramertj

This comment has been minimized.

Copy link
Member

commented May 23, 2019

@nikomatsakis Looks like @wycats's error was the same, it's just that the output type of the future is more complicated (Pin<Box<Stream<Item = Value> + Send + 'static>>).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.