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

Too many type inside async object must be known in this context errors #66445

Open
olegnn opened this issue Nov 15, 2019 · 4 comments
Open

Too many type inside async object must be known in this context errors #66445

olegnn opened this issue Nov 15, 2019 · 4 comments
Assignees
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@olegnn
Copy link
Contributor

olegnn commented Nov 15, 2019

This code (Playground)

use futures::stream::{iter/*, StreamExt*/};

async fn produce_11_errors() {
    iter(vec![1, 2, 3])/*.collect::<Vec<_>>()*/.await;
}

fn main() {}

currently produces 11 errors:

  • 1 of the trait bound is not satisfied
  • 10 of type inside async object must be known in this context.

If you add elements to vec, it will generate even more.

@jonas-schievink jonas-schievink added A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 15, 2019
@nikomatsakis nikomatsakis added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Nov 19, 2019
@estebank estebank added the D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. label Dec 3, 2019
@doc-jones
Copy link

@rustbot claim

@estebank
Copy link
Contributor

estebank commented Dec 9, 2021

Current output since 1.54:

error[E0277]: `futures::stream::Iter<std::vec::IntoIter<{integer}>>` is not a future
 --> src/main.rs:4:5
  |
4 |     iter(vec![1, 2, 3])/*.collect::<Vec<_>>()*/.await;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `futures::stream::Iter<std::vec::IntoIter<{integer}>>` is not a future
  |
  = help: the trait `futures::Future` is not implemented for `futures::stream::Iter<std::vec::IntoIter<{integer}>>`
  = note: futures::stream::Iter<std::vec::IntoIter<{integer}>> must be a future or must implement `IntoFuture` to be awaited
  = note: required because of the requirements on the impl of `std::future::IntoFuture` for `futures::stream::Iter<std::vec::IntoIter<{integer}>>`

@olegnn are there other changes you'd like to see here?

@estebank estebank added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 9, 2021
@olegnn
Copy link
Contributor Author

olegnn commented Dec 21, 2021

@estebank now it looks much better!

However, code like this still produces the same error twice

use futures::stream::*;

async fn same_error_twice() -> Vec<u8> {
    once(async { 0.0 }).collect().await
}

fn main() {}
error[E0277]: the trait bound `Vec<u8>: Extend<{float}>` is not satisfied
  --> src/main.rs:4:5
   |
4  |     once(async { 0.0 }).collect().await
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Extend<{float}>` is not implemented for `Vec<u8>`
   |
   = help: the following implementations were found:
             <Vec<T, A> as Extend<&'a T>>
             <Vec<T, A> as Extend<T>>
   = note: required because of the requirements on the impl of `futures::Future` for `Collect<futures::stream::Once<impl futures::Future>, Vec<u8>>`
note: required by `futures::Future::poll`

error[E0277]: the trait bound `Vec<u8>: Extend<{float}>` is not satisfied
 --> src/main.rs:4:25
  |
4 |     once(async { 0.0 }).collect().await
  |                         ^^^^^^^ the trait `Extend<{float}>` is not implemented for `Vec<u8>`
  |
  = help: the following implementations were found:
            <Vec<T, A> as Extend<&'a T>>
            <Vec<T, A> as Extend<T>>

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to 2 previous errors

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a63224be65d4e278f12786dc0dd497fd

@estebank
Copy link
Contributor

Current output:

error[E0277]: the trait bound `Vec<u8>: Extend<{float}>` is not satisfied
 --> src/main.rs:4:34
  |
4 |     once(async { 0.0 }).collect().await
  |                                  ^^^^^^ the trait `Extend<{float}>` is not implemented for `Vec<u8>`
  |
  = help: the following other types implement trait `Extend<A>`:
            <Vec<T, A> as Extend<&'a T>>
            <Vec<T, A> as Extend<T>>
  = note: required for `Collect<futures::stream::Once<[async block@src/main.rs:4:10: 4:23]>, Vec<u8>>` to implement `futures::Future`

error[E0277]: the trait bound `Vec<u8>: Extend<{float}>` is not satisfied
   --> src/main.rs:4:25
    |
4   |     once(async { 0.0 }).collect().await
    |                         ^^^^^^^ the trait `Extend<{float}>` is not implemented for `Vec<u8>`
    |
    = help: the following other types implement trait `Extend<A>`:
              <Vec<T, A> as Extend<&'a T>>
              <Vec<T, A> as Extend<T>>
note: required by a bound in `futures::StreamExt::collect`
   --> /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.25/src/stream/stream/mod.rs:516:29
    |
516 |     fn collect<C: Default + Extend<Self::Item>>(self) -> Collect<Self, C>
    |                             ^^^^^^^^^^^^^^^^^^ required by this bound in `StreamExt::collect`

I wonder if we could extend the current deduplication logic to account for expressions and look at earlier errors in method chains...

@JohnTitor JohnTitor removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 5, 2023
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 A-inference Area: Type inference AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Claimed
Development

No branches or pull requests

6 participants