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: implementation of std::iter::Iterator is not general enough #72167

Closed
andreytkachenko opened this issue May 13, 2020 · 1 comment
Closed
Labels
C-bug Category: This is a bug.

Comments

@andreytkachenko
Copy link

I tried this code:

use futures::stream::StreamExt; 
async fn test() {
    let data = std::sync::Arc::new(vec![1i32,2,3,4]);
    
    tokio::spawn(async move {
        futures::stream::iter(data.iter())
            .map(|_| async move {
                12i32
            })
            .buffer_unordered(32usize)
            .collect::<Vec<_>>()
            .await;
    });
}

I expected to see this happen: compiled

Instead, this happened: compilation failed with error:

error: implementation of `std::iter::Iterator` is not general enough
    --> src/main.rs:9:5
     |
9    |       tokio::spawn(async move {
     |       ^^^^^^^^^^^^ implementation of `std::iter::Iterator` is not general enough
     |
     = note: `std::iter::Iterator` would have to be implemented for the type `std::slice::Iter<'0, i32>`, for any lifetime `'0`...
     = note: ...but `std::iter::Iterator` is actually implemented for the type `std::slice::Iter<'1, i32>`, for some specific lifetime `'1`

Meta

rustc --version --verbose:

rustc 1.43.0 (4fb7144ed 2020-04-20)
binary: rustc
commit-hash: 4fb7144ed159f94491249e86d5bbd033b5d60550
commit-date: 2020-04-20
host: x86_64-unknown-linux-gnu
release: 1.43.0
LLVM version: 9.0

Notes

This code compiles:

use futures::stream::{Stream, StreamExt};
use std::future::Future;

fn make_stream<'a>(i: std::slice::Iter<'a, i32>) -> impl Future<Output = Vec<i32>> + 'a {
    futures::stream::iter(i)
        .map(|_| async move { 12i32 })
        .buffer_unordered(32usize)
        .collect::<Vec<i32>>()
}

async fn test() {
    tokio::spawn(async move {
        let data = vec![1i32, 2, 3, 4];
        make_stream(data.iter()).await;
    });
}

@andreytkachenko andreytkachenko added the C-bug Category: This is a bug. label May 13, 2020
@jonas-schievink
Copy link
Contributor

Duplicate of #71671

@jonas-schievink jonas-schievink marked this as a duplicate of #71671 May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants