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

Error in `async` function/block produces errors for valid unrelated expressions #66634

Open
olegnn opened this issue Nov 22, 2019 · 0 comments

Comments

@olegnn
Copy link
Contributor

@olegnn olegnn commented Nov 22, 2019

Code (Playground)

use futures::{future::ready, join};

async fn _incorrect_error() {
    join! { ready(0) };
    // Produces cannot infer type for `{integer}` for expression above
    0.await;
}

fn main() {}

produces following errors:

Errors

error[E0277]: the trait bound `{integer}: core::future::future::Future` is not satisfied
  --> src/main.rs:6:5
   |
6  |     0.await;
   |     ^^^^^^^ the trait `core::future::future::Future` is not implemented for `{integer}`
   |
   = help: the following implementations were found:
             <&mut F as core::future::future::Future>
             <futures_channel::oneshot::Receiver<T> as core::future::future::Future>
             <futures_task::future_obj::FutureObj<'_, T> as core::future::future::Future>
             <futures_task::future_obj::LocalFutureObj<'_, T> as core::future::future::Future>
           and 84 others

error[E0698]: type inside `async fn` body must be known in this context
 --> src/main.rs:4:5
  |
4 |     join! { ready(0) };
  |     ^^^^^^^^^^^^^^^^^^^ cannot infer type for `{integer}`
  |
note: the type is part of the `async fn` body because of this `await`
 --> src/main.rs:4:5
  |
4 |     join! { ready(0) };
  |     ^^^^^^^^^^^^^^^^^^^
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0698]: type inside `async fn` body must be known in this context
 --> src/main.rs:4:5
  |
4 |     join! { ready(0) };
  |     ^^^^^^^^^^^^^^^^^^^ cannot infer type for `{integer}`
  |
note: the type is part of the `async fn` body because of this `await`
 --> src/main.rs:4:5
  |
4 |     join! { ready(0) };
  |     ^^^^^^^^^^^^^^^^^^^
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0698]: type inside `async fn` body must be known in this context
 --> src/main.rs:4:5
  |
4 |     join! { ready(0) };
  |     ^^^^^^^^^^^^^^^^^^^ cannot infer type for `{integer}`
  |
note: the type is part of the `async fn` body because of this `await`
 --> src/main.rs:4:5
  |
4 |     join! { ready(0) };
  |     ^^^^^^^^^^^^^^^^^^^
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0698]: type inside `async fn` body must be known in this context
 --> src/main.rs:6:5
  |
6 |     0.await;
  |     ^ cannot infer type for `{integer}`
  |
note: the type is part of the `async fn` body because of this `await`
 --> src/main.rs:6:5
  |
6 |     0.await;
  |     ^^^^^^^

error[E0698]: type inside `async fn` body must be known in this context
 --> src/main.rs:6:5
  |
6 |     0.await;
  |     ^^^^^^^ cannot infer type for `{integer}`
  |
note: the type is part of the `async fn` body because of this `await`
 --> src/main.rs:6:5
  |
6 |     0.await;
  |     ^^^^^^^

However, if we remove line

0.await;

, it will become valid. Error on this line affects unrelated

join! { ready(0) };

and produces cannot infer type for {integer} error for valid expression. This behaviour could seem not so bad, but imagine large async function with many lines (you can simply copy-paste first line several times and look to the output).

@olegnn olegnn changed the title Type error in `async` function produces errors in valid unrelated expressions Type error in `async` function produces errors for valid unrelated expressions Nov 22, 2019
@olegnn olegnn changed the title Type error in `async` function produces errors for valid unrelated expressions Error in `async` function produces errors for valid unrelated expressions Nov 22, 2019
@olegnn olegnn changed the title Error in `async` function produces errors for valid unrelated expressions Error in `async` function/block produces errors for valid unrelated expressions Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.