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

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

Closed
jimblandy opened this issue May 2, 2020 · 1 comment · Fixed by #71948
Closed

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

jimblandy opened this issue May 2, 2020 · 1 comment · Fixed by #71948
Assignees
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jimblandy
Copy link
Contributor

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

@jimblandy jimblandy added the C-bug Category: This is a bug. label May 2, 2020
@jimblandy
Copy link
Contributor Author

Related: #61076

@jonas-schievink jonas-schievink added A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels May 2, 2020
@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label May 5, 2020
@csmoe csmoe self-assigned this May 6, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 15, 2020
@bors bors closed this as completed in badcf26 May 16, 2020
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue May 16, 2020
Suggest to await future before ? operator

Closes rust-lang/rust#71811
cc #61076
phansch pushed a commit to phansch/rust-clippy that referenced this issue May 24, 2020
Suggest to await future before ? operator

Closes rust-lang/rust#71811
cc #61076
@tmandry tmandry moved this to Done in wg-async work Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants