Skip to content

suggest await for future-related type errors #61076

Closed

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

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

    @nikomatsakis
    ContributorAuthor

    cc @rust-lang/wg-diagnostics @estebank

  3. 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
  4. 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?

  5. 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?.

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

  7. cofibrant commented on Jun 17, 2019

    @cofibrant
    Contributor

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

  8. 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.

  9. cofibrant commented on Jun 17, 2019

    @cofibrant
    Contributor

    @rustbot claim

  10. self-assigned this
    on Jun 17, 2019
  11. added 3 commits that reference this issue on Jun 27, 2019
  12. 11 remaining items

  13. jebrosen commented on May 11, 2020

    @jebrosen
    Contributor

    Here's another example where suggesting .await would be helpful (playground):

    async fn a() -> Result<(), ()> {
        Ok(())
    }
    
    fn main() {
        match a() {
            Ok(()) => (),
            Err(()) => (),
        }
    }
  14. added 2 commits that reference this issue on May 15, 2020
  15. added a commit that references this issue on May 17, 2020
  16. tmandry commented on May 19, 2020

    @tmandry
    Member

    @csmoe Thanks for improving on this with #71948. Do you want to continue working on this, or release the assignment for now?

  17. csmoe commented on May 20, 2020

    @csmoe
    Contributor

    @tmandry I'll try to fix them all, more commits pending.

  18. csmoe commented on May 20, 2020

    @csmoe
    Contributor

    From #62067, these are the cases still missing:

    * [ ]  Return places for functions
    
    * [ ]  Field access
    
    * [ ]  Method invocation
    

    In bodies that aren't async, .await is not suggested, but maybe we should mention that we're not in an async block and that the future could have been awaited. I guess this is likely to be a common wip error during development.

    @estebank could you write a case of return-place-for-functions? I'm not sure about this one, since await seems already suggested

  19. estebank commented on May 20, 2020

    @estebank
    Contributor

    Indeed. I'm not sure if it is due to an improvement since august last year, or just a mistake on my part. Either way, we are in a good place today :)

  20. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Jun 11, 2020
  21. tmandry commented on Jul 14, 2020

    @tmandry
    Member

    Ping from wg-async-foundations triage. @csmoe are you still working on this?

  22. csmoe commented on Jul 15, 2020

    @csmoe
    Contributor

    @tmandry yes, in slow progress since time is tough these days.

  23. added a commit that references this issue on Aug 27, 2020
    f7cbb7a
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

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions