Closed
Description
I'm struggling with types in async code, and came across an error that was very misleading. I tried this code:
fn run(&self) -> Box<Future<Item = (), Error = ()>> {
let (writer, reader) = self.socket.framed(transport::new()).split();
Box::new(
writer
.send_all(reader.and_then(move |req| future::ok(req)))
.then(move |_| {
debug!("connection to neighbor {:?} closed", self.peer);
Ok(())
})
.then(|_: ()| Ok(())), // XXX
)
}
I expected to see an error that my closure on the line annotated with "XXX" has the wrong argument type.
Instead, this happened:
error[E0593]: closure takes 0 arguments but 1 argument is required
--> src/net/mod.rs:82:18
|
82 | .then(|_: ()| Ok(())), // XXX
| ^^^^ -------------- takes 0 arguments
| |
| expected closure that takes 1 argument
error[E0593]: closure takes 0 arguments but 1 argument is required
--> src/net/mod.rs:75:9
|
75 | / Box::new(
76 | | writer
77 | | .send_all(reader.and_then(move |req| future::ok(req)))
78 | | .then(move |_| {
... |
82 | | .then(|_: ()| Ok(())), // XXX
| | -------------- takes 0 arguments
83 | | )
| |_________^ expected closure that takes 1 argument
|
= note: required because of the requirements on the impl of `futures::Future` for `futures::Then<futures::Then<futures::sink::SendAll<futures::stream::SplitSink<tokio_io::codec::Framed<tokio_core::net::TcpStream, net::transport::Codec>>, futures::stream::AndThen<futures::stream::SplitStream<tokio_io::codec::Framed<tokio_core::net::TcpStream, net::transport::Codec>>, [closure@src/net/mod.rs:77:43: 77:69], futures::FutureResult<std::string::String, std::io::Error>>>, std::result::Result<(), _>, [closure@src/net/mod.rs:78:23: 81:18 self:_]>, std::result::Result<(), ()>, [closure@src/net/mod.rs:82:23: 82:37]>`
= note: required for the cast to the object type `futures::Future<Error=(), Item=()>`
Meta
dustin@jemison ~/p/rubbish [issue14*] $ rustc --version --verbose
rustc 1.21.0 (3b72af97e 2017-10-09)
binary: rustc
commit-hash: 3b72af97e42989b2fe104d8edbaee123cdf7c58f
commit-date: 2017-10-09
host: x86_64-unknown-linux-gnu
release: 1.21.0
LLVM version: 4.0
/cc @Mark-Simulacrum