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 A-diagnostics AsyncAwait-Triaged C-enhancement T-compiler

Comments

@jimblandy
Copy link
Contributor

@jimblandy jimblandy commented May 2, 2020

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 label May 2, 2020
@jimblandy
Copy link
Contributor Author

@jimblandy jimblandy commented May 2, 2020

Related: #61076

@jonas-schievink jonas-schievink added A-async-await A-diagnostics C-enhancement T-compiler and removed C-bug labels May 2, 2020
@tmandry tmandry added this to On deck in wg-async work via automation May 5, 2020
@tmandry tmandry added the AsyncAwait-Triaged label May 5, 2020
@csmoe csmoe self-assigned this May 6, 2020
@csmoe csmoe moved this from On deck to Claimed in wg-async work May 6, 2020
@csmoe csmoe moved this from Claimed to In progress in wg-async work 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
wg-async work automation moved this from In progress to Done 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await A-diagnostics AsyncAwait-Triaged C-enhancement T-compiler
Projects
Development

Successfully merging a pull request may close this issue.

4 participants