rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.39k stars 625 forks source link

"error: reached the recursion limit during monomorphization (selection ambiguity)" with chunks #393

Closed conradev closed 7 years ago

conradev commented 7 years ago

Compiling the following code fails with:

error: reached the recursion limit during monomorphization (selection ambiguity)
extern crate futures; // 0.1.10

use futures::{stream, Stream, Future};
use futures::sync::oneshot;

fn main() {
    let (tx, rx) = oneshot::channel(); // future to fetch a collection of objects
    tx.complete((0..200).collect());

    rx.map(|l: Vec<usize>| stream::iter(l.into_iter().map(|i| Ok(i))))
        .flatten_stream()
        .chunks(50)
        .map(|i| Ok(i)) // do work with batch of objects
        .buffer_unordered(5)
        .collect();
}
rustc 1.15.0 (10893a9a3 2017-01-19)

The idea here is to batch process a bunch of objects. If I remove the chunks(50) line, the code successfully compiles 😮

dwrensha commented 7 years ago

Possibly related to #367.

conradev commented 7 years ago

Some more info:

alexcrichton commented 7 years ago

I wonder if this may be a bug in the compiler? We've caught some before through this library. It'd be helpful to reduce the library to the bare bones though to see what's necessary to trigger the bug.

alexcrichton commented 7 years ago

Ok I've reduced it at https://github.com/rust-lang/rust/issues/40003

goffrie commented 7 years ago

I suppose this issue can be closed now?