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

reached the recursion limit during monomorphization (selection ambiguity) #262

Closed weiznich closed 7 years ago

weiznich commented 7 years ago

Compiling some futures related code fails with: error: reached the recursion limit during monomorphization (selection ambiguity)

extern crate futures; // 0.1.6
extern crate futures_cpupool; // 0.1.2

use futures::Future;
use futures_cpupool::CpuPool;

const MAX: usize = 10;

fn work(n: u32) -> Result<u32, ()> {
    ::std::thread::sleep_ms(n * 2);
    Ok(n)
}

fn fold_b(a: u64, b: u32) -> u64 {
    ::std::thread::sleep_ms(b);
    a + b as u64
}

fn main() {
    let pool = CpuPool::new_num_cpus();
    let data = (0..MAX).rev().collect::<Vec<_>>();
    let a = {
        let workers = data.clone()
            .into_iter()
            .map(|d| pool.spawn_fn(move || work(d as u32)));
        ::futures::collect(workers).wait().unwrap().into_iter().fold(0, fold_b)
    };
}

rustc --version rustc 1.15.0-nightly (d9bdc636d 2016-11-24)

weiznich commented 7 years ago

It seems that this was introduced between version 0.1.3 and version 0.1.4.

alexcrichton commented 7 years ago

I've opened https://github.com/rust-lang/rust/issues/38033 to track this

dwrensha commented 7 years ago

This particular instance of the error appears to have been eliminated, so I think it makes sense to close this issue.

I've found another instance of this error message and reported it as https://github.com/alexcrichton/futures-rs/issues/367.

alexcrichton commented 7 years ago

Oops forgot to close this with @dwrensha's last comment.