Skip to content

rustc doesn't suggest missing .await before a ? #71811

Closed

Description

@jimblandy

When I compile the following code:

async fn fallible() -> Result<(), ()> { Ok(()) }

async fn caller() -> Result<(), ()> {
    fallible() /* mising .await */ ?;
    Ok(())
}

fn main() -> Result<(), ()> {
    futures::executor::block_on(caller())
}

rustc says:

error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
 --> src/main.rs:4:5
  |
4 |     fallible() /* mising .await */ ?;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `impl core::future::future::Future`
  |
  = help: the trait `std::ops::Try` is not implemented for `impl core::future::future::Future`
  = note: required by `std::ops::Try::into_result`

I think it should notice that the program is trying to apply ? to a future, and suggest awaiting it.

(If there is an existing issue for this, it is not labeled A-async-await and A-suggestion-diagnostics.)

Activity

  1. jimblandy commented on May 2, 2020

    @jimblandy
    ContributorAuthor

    Related: #61076

  2. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    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.
    and removed
    C-bugCategory: This is a bug.
    on May 2, 2020
  3. added
    AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.
    on May 5, 2020
  4. self-assigned this
    on May 6, 2020
  5. added 2 commits that reference this issue on May 15, 2020
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