Skip to content

suggest await for future-related type errors #61076

Closed
@nikomatsakis

Description

@nikomatsakis

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.

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 23, 2019
nikomatsakis

nikomatsakis commented on May 23, 2019

@nikomatsakis
ContributorAuthor

cc @rust-lang/wg-diagnostics @estebank

added
A-diagnosticsArea: Messages for errors, warnings, and lints
AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.
on May 23, 2019
nikomatsakis

nikomatsakis commented on May 23, 2019

@nikomatsakis
ContributorAuthor

@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

estebank commented on May 23, 2019

@estebank
Contributor

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

cramertj commented on May 23, 2019

@cramertj
Member

@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>>).

cofibrant

cofibrant commented on Jun 17, 2019

@cofibrant
Contributor

Hi, I'd be really interested in working on this

davidtwco

davidtwco commented on Jun 17, 2019

@davidtwco
Member

@doctorn awesome! Sending @rustbot claim should assign you to the issue and feel free to start a topic in the #wg-async-foundations stream if you need a hand.

cofibrant

cofibrant commented on Jun 17, 2019

@cofibrant
Contributor

@rustbot claim

self-assigned this
on Jun 17, 2019
added 2 commits that reference this issue on Jun 27, 2019

Rollup merge of rust-lang#62067 - doctorn:await_diagnostic, r=matthew…

ceb4805

Rollup merge of rust-lang#62067 - doctorn:await_diagnostic, r=matthew…

2cdfff8

31 remaining items

Loading
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 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

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    suggest `await` for future-related type errors · Issue #61076 · rust-lang/rust