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

Async blocks are leaky about wording wrt. `?` in diagnostics #62570

Open
Centril opened this issue Jul 10, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@Centril
Copy link
Member

commented Jul 10, 2019

E.g. consider:

#![feature(async_await)]

fn foo() {
    let x = async move {
        Err(())?;

        1
    };
}

which yields the diagnostic:

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
 --> src/lib.rs:5:9
  |
5 |         Err(())?;
  |         ^^^^^^^^ cannot use the `?` operator in a function that returns `{integer}`
  |
  = help: the trait `std::ops::Try` is not implemented for `{integer}`
  = note: required by `std::ops::Try::from_error`

Ostensibly the user might think of fn foo as "the function" but it is in fact the async block that is "the function" here. That seems like something which would confuse users who are not familiar with the lowering and whatnot (most users).

@theduke

This comment has been minimized.

Copy link
Contributor

commented Jul 11, 2019

I ran into this.

It's much more confusing if the outer function actually returns a result.

In a more complicated function the error message can be a real head scratcher.

#![feature(async_await)]

async fn f() -> Result<bool, ()> {
    async {
        Err(())?
    }.await;
    
    Ok(true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.