Compiler error: E0275]: overflow evaluating the requirement

I am trying to use trustdns-resolver and get:
error[E0275]: overflow evaluating the requirement failure::Backtrace: std::marker::Send``
It seems the reason is in very deep generic nesting inside in trustdns code.

Code: https://github.com/vchekan/kafka4rust/tree/02d279e7b1276ce7464924f246a14cbaeb53b61b

I am not sure, is it compiler, me or trust-dns?

rustc 1.30.0-nightly (b2028828d 2018-08-16)

error[E0275]: overflow evaluating the requirement `failure::Backtrace: std::marker::Send`
   --> src/cluster.rs:115:9
    |
115 |         tokio::run(bs);
    |         ^^^^^^^^^^
    |
    = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
    = note: required because it appears within the type `failure::context::Either<failure::Backtrace, failure::Error>`
    = note: required because it appears within the type `failure::Context<trust_dns_proto::error::ProtoErrorKind>`
    = note: required because it appears within the type `trust_dns_proto::error::ProtoError`
    = note: required because it appears within the type `std::result::Result<trust_dns_proto::xfer::dns_response::DnsResponse, trust_dns_proto::error::ProtoError>`
    = note: required because it appears within the type `std::option::Option<std::result::Result<trust_dns_proto::xfer::dns_response::DnsResponse, trust_dns_proto::error::ProtoError>>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `futures::lock::Lock<std::option::Option<std::result::Result<trust_dns_proto::xfer::dns_response::DnsResponse, trust_dns_proto::error::ProtoError>>>`
    = note: required because it appears within the type `futures::sync::oneshot::Inner<std::result::Result<trust_dns_proto::xfer::dns_response::DnsResponse, trust_dns_proto::error::ProtoError>>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<futures::sync::oneshot::Inner<std::result::Result<trust_dns_proto::xfer::dns_response::DnsResponse, trust_dns_proto::error::ProtoError>>>`
    = note: required because it appears within the type `futures::Receiver<std::result::Result<trust_dns_proto::xfer::dns_response::DnsResponse, trust_dns_proto::error::ProtoError>>`
    = note: required because it appears within the type `trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponseInner`
    = note: required because it appears within the type `trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse`
    = note: required because it appears within the type `std::option::Option<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `futures::lock::Lock<std::option::Option<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>>`
    = note: required because it appears within the type `futures::sync::oneshot::Inner<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<futures::sync::oneshot::Inner<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>>`
    = note: required because it appears within the type `futures::Sender<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>`
    = note: required because it appears within the type `trust_dns_proto::xfer::OneshotDnsRequest<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `futures::sync::mpsc::Inner<trust_dns_proto::xfer::OneshotDnsRequest<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<futures::sync::mpsc::Inner<trust_dns_proto::xfer::OneshotDnsRequest<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>>>`
    = note: required because it appears within the type `futures::sync::mpsc::Sender<trust_dns_proto::xfer::OneshotDnsRequest<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>>`
    = note: required because it appears within the type `futures::sync::mpsc::UnboundedSender<trust_dns_proto::xfer::OneshotDnsRequest<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>>`
    = note: required because it appears within the type `trust_dns_proto::xfer::DnsRequestStreamHandle<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>`
    = note: required because it appears within the type `trust_dns_proto::xfer::BufDnsRequestStreamHandle<trust_dns_proto::xfer::dns_multiplexer::DnsMultiplexerSerialResponse>`
    = note: required because it appears within the type `trust_dns_resolver::name_server_pool::ConnectionHandle`
    = note: required because it appears within the type `trust_dns_resolver::name_server_pool::NameServer<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<trust_dns_resolver::name_server_pool::NameServer<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>>`
    = note: required because it appears within the type `alloc::raw_vec::RawVec<trust_dns_resolver::name_server_pool::NameServer<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>>`
    = note: required because it appears within the type `std::vec::Vec<trust_dns_resolver::name_server_pool::NameServer<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Mutex<std::vec::Vec<trust_dns_resolver::name_server_pool::NameServer<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>>>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<std::sync::Mutex<std::vec::Vec<trust_dns_resolver::name_server_pool::NameServer<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>>>>`
    = note: required because it appears within the type `trust_dns_resolver::name_server_pool::NameServerPool<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>`
    = note: required because it appears within the type `trust_dns_proto::xfer::retry_dns_handle::RetryDnsHandle<trust_dns_resolver::name_server_pool::NameServerPool<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>>`
    = note: required because it appears within the type `trust_dns_resolver::lookup::LookupEither<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>`
    = note: required because it appears within the type `trust_dns_resolver::lookup_state::CachingClient<trust_dns_resolver::lookup::LookupEither<trust_dns_resolver::name_server_pool::ConnectionHandle, trust_dns_resolver::name_server_pool::StandardConnection>>`
    = note: required because it appears within the type `trust_dns_resolver::lookup_ip::LookupIpFuture`
    = note: required because it appears within the type `std::option::Option<trust_dns_resolver::lookup_ip::LookupIpFuture>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `futures::lock::Lock<std::option::Option<trust_dns_resolver::lookup_ip::LookupIpFuture>>`
    = note: required because it appears within the type `futures::sync::oneshot::Inner<trust_dns_resolver::lookup_ip::LookupIpFuture>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<futures::sync::oneshot::Inner<trust_dns_resolver::lookup_ip::LookupIpFuture>>`
    = note: required because it appears within the type `futures::Receiver<trust_dns_resolver::lookup_ip::LookupIpFuture>`
    = note: required because it appears within the type `futures::MapErr<futures::Receiver<trust_dns_resolver::lookup_ip::LookupIpFuture>, fn(futures::Canceled) -> trust_dns_resolver::error::ResolveError>`
    = note: required because it appears within the type `futures::future::chain::Chain<futures::MapErr<futures::Receiver<trust_dns_resolver::lookup_ip::LookupIpFuture>, fn(futures::Canceled) -> trust_dns_resolver::error::ResolveError>, trust_dns_resolver::lookup_ip::LookupIpFuture, fn(trust_dns_resolver::lookup_ip::LookupIpFuture) -> trust_dns_resolver::lookup_ip::LookupIpFuture>`
    = note: required because it appears within the type `futures::AndThen<futures::MapErr<futures::Receiver<trust_dns_resolver::lookup_ip::LookupIpFuture>, fn(futures::Canceled) -> trust_dns_resolver::error::ResolveError>, trust_dns_resolver::lookup_ip::LookupIpFuture, fn(trust_dns_resolver::lookup_ip::LookupIpFuture) -> trust_dns_resolver::lookup_ip::LookupIpFuture>`
    = note: required because it appears within the type `futures::future::Either<futures::AndThen<futures::MapErr<futures::Receiver<trust_dns_resolver::lookup_ip::LookupIpFuture>, fn(futures::Canceled) -> trust_dns_resolver::error::ResolveError>, trust_dns_resolver::lookup_ip::LookupIpFuture, fn(trust_dns_resolver::lookup_ip::LookupIpFuture) -> trust_dns_resolver::lookup_ip::LookupIpFuture>, futures::FutureResult<trust_dns_resolver::lookup_ip::LookupIp, trust_dns_resolver::error::ResolveError>>`
    = note: required because it appears within the type `trust_dns_resolver::Background<trust_dns_resolver::lookup_ip::LookupIpFuture>`
    = note: required because it appears within the type `futures::Map<trust_dns_resolver::Background<trust_dns_resolver::lookup_ip::LookupIpFuture>, [closure@src/connection.rs:77:17: 80:14 port:&'static u16]>`
    = note: required because it appears within the type `futures::MapErr<futures::Map<trust_dns_resolver::Background<trust_dns_resolver::lookup_ip::LookupIpFuture>, [closure@src/connection.rs:77:17: 80:14 port:&'static u16]>, [closure@src/connection.rs:81:21: 81:40]>`
    = note: required because it appears within the type `impl futures::Future`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<impl futures::Future>`
    = note: required because it appears within the type `alloc::raw_vec::RawVec<impl futures::Future>`
    = note: required because it appears within the type `std::vec::Vec<impl futures::Future>`
    = note: required because it appears within the type `futures::SelectOk<impl futures::Future>`
    = note: required because it appears within the type `futures::future::chain::Chain<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>`
    = note: required because it appears within the type `futures::AndThen<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>`
    = note: required because it appears within the type `futures::future::chain::Chain<futures::AndThen<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>, futures::MapErr<tokio::io::WriteAll<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:74:42: 74:75]>, [closure@src/cluster.rs:68:18: 75:10 topics:std::vec::Vec<std::string::String>]>`
    = note: required because it appears within the type `futures::AndThen<futures::AndThen<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>, futures::MapErr<tokio::io::WriteAll<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:74:42: 74:75]>, [closure@src/cluster.rs:68:18: 75:10 topics:std::vec::Vec<std::string::String>]>`
    = note: required because it appears within the type `futures::future::chain::Chain<futures::AndThen<futures::AndThen<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>, futures::MapErr<tokio::io::WriteAll<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:74:42: 74:75]>, [closure@src/cluster.rs:68:18: 75:10 topics:std::vec::Vec<std::string::String>]>, futures::MapErr<tokio::io::ReadExact<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:80:25: 80:58]>, [closure@src/cluster.rs:76:18: 81:10]>`
    = note: required because it appears within the type `futures::AndThen<futures::AndThen<futures::AndThen<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>, futures::MapErr<tokio::io::WriteAll<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:74:42: 74:75]>, [closure@src/cluster.rs:68:18: 75:10 topics:std::vec::Vec<std::string::String>]>, futures::MapErr<tokio::io::ReadExact<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:80:25: 80:58]>, [closure@src/cluster.rs:76:18: 81:10]>`
    = note: required because it appears within the type `futures::future::chain::Chain<futures::AndThen<futures::AndThen<futures::AndThen<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>, futures::MapErr<tokio::io::WriteAll<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:74:42: 74:75]>, [closure@src/cluster.rs:68:18: 75:10 topics:std::vec::Vec<std::string::String>]>, futures::MapErr<tokio::io::ReadExact<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:80:25: 80:58]>, [closure@src/cluster.rs:76:18: 81:10]>, futures::MapErr<tokio::io::ReadExact<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:86:25: 86:58]>, [closure@src/cluster.rs:81:21: 87:10]>`
    = note: required because it appears within the type `futures::AndThen<futures::AndThen<futures::AndThen<futures::AndThen<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>, futures::MapErr<tokio::io::WriteAll<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:74:42: 74:75]>, [closure@src/cluster.rs:68:18: 75:10 topics:std::vec::Vec<std::string::String>]>, futures::MapErr<tokio::io::ReadExact<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:80:25: 80:58]>, [closure@src/cluster.rs:76:18: 81:10]>, futures::MapErr<tokio::io::ReadExact<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:86:25: 86:58]>, [closure@src/cluster.rs:81:21: 87:10]>`
    = note: required because it appears within the type `futures::Map<futures::AndThen<futures::AndThen<futures::AndThen<futures::AndThen<futures::SelectOk<impl futures::Future>, futures::MapErr<tokio::net::ConnectFuture, [closure@src/cluster.rs:47:51: 49:18]>, [closure@src/cluster.rs:46:22: 50:14]>, futures::MapErr<tokio::io::WriteAll<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:74:42: 74:75]>, [closure@src/cluster.rs:68:18: 75:10 topics:std::vec::Vec<std::string::String>]>, futures::MapErr<tokio::io::ReadExact<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:80:25: 80:58]>, [closure@src/cluster.rs:76:18: 81:10]>, futures::MapErr<tokio::io::ReadExact<tokio::net::TcpStream, std::vec::Vec<u8>>, [closure@src/cluster.rs:86:25: 86:58]>, [closure@src/cluster.rs:81:21: 87:10]>, [closure@src/cluster.rs:87:16: 92:10]>`
    = note: required because it appears within the type `impl futures::Future`
    = note: required because it appears within the type `futures::Map<impl futures::Future, [closure@src/cluster.rs:108:17: 110:14]>`
    = note: required because it appears within the type `futures::MapErr<futures::Map<impl futures::Future, [closure@src/cluster.rs:108:17: 110:14]>, [closure@src/cluster.rs:111:21: 113:14]>`
    = note: required by `tokio::run`

Did you try increasing the recursion limit as the error suggests? I’m on mobile so a bit hard to tell, but it doesn’t look like the compiler hit an actual cycle.

Well, putting recommended recursion_limit did help, but it is still strange to have such message. So did compiler authors did not anticipate not so uncommon use case or did library author abuse generics in unusual way?

I think compiler authors did anticipate this, and that’s why there’s a configurable recursion limit.

It isn’t too difficult to bump into this when using futures - “all” it takes is for a fairly lengthy combinator chain that involves deeply nested captured types in the closures, which appears to be the case here.

I can’t speak to whether trust_dns went overboard with generics as I’m not familiar with its code.