From 8a01cddbcbd6a4dd23a3958c67ab8b187fee1d62 Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Sun, 12 May 2019 21:22:34 +0300 Subject: [PATCH 1/4] added #[must_use] for impl Future structs --- examples/guessing.rs | 2 +- examples/tcp-echo.rs | 2 +- src/net/tcp.rs | 2 ++ src/net/udp.rs | 2 ++ src/task.rs | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/guessing.rs b/examples/guessing.rs index a074fa9d..b8b6eff6 100644 --- a/examples/guessing.rs +++ b/examples/guessing.rs @@ -63,7 +63,7 @@ async fn main() -> Result<(), failure::Error> { let mut incoming = listener.incoming(); while let Some(stream) = incoming.next().await { - runtime::spawn(play(stream?)); + runtime::spawn(play(stream?)).await?; } Ok(()) } diff --git a/examples/tcp-echo.rs b/examples/tcp-echo.rs index 26a34959..b24a66cd 100644 --- a/examples/tcp-echo.rs +++ b/examples/tcp-echo.rs @@ -23,7 +23,7 @@ async fn main() -> std::io::Result<()> { let (reader, writer) = &mut stream.split(); reader.copy_into(writer).await?; Ok::<(), std::io::Error>(()) - }); + }).await?; } Ok(()) } diff --git a/src/net/tcp.rs b/src/net/tcp.rs index f1bc14b9..4af95153 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -217,6 +217,7 @@ impl AsyncWrite for TcpStream { /// /// [`TcpStream::connect`]: struct.TcpStream.html#method.connect /// [`TcpStream`]: struct.TcpStream.html +#[must_use] pub struct Connect { addrs: Option>>, last_err: Option, @@ -452,6 +453,7 @@ impl TcpListener { /// /// [`TcpStream::accept`]: struct.TcpStream.html#method.accept /// [`TcpStream`]: struct.TcpStream.html +#[must_use] #[derive(Debug)] pub struct Accept<'stream> { inner: Incoming<'stream>, diff --git a/src/net/udp.rs b/src/net/udp.rs index 5f87d16e..c6b5cd2c 100644 --- a/src/net/udp.rs +++ b/src/net/udp.rs @@ -358,6 +358,7 @@ impl UdpSocket { /// On success, returns the number of bytes written. /// /// [`UdpSocket::send_to`]: struct.UdpSocket.html#method.send_to +#[must_use] #[derive(Debug)] pub struct SendTo<'socket, 'buf> { /// The open socket we use to send the message from. @@ -392,6 +393,7 @@ impl<'socket, 'buf> Future for SendTo<'socket, 'buf> { /// On success, returns the number of bytes read and the origin. /// /// [`UdpSocket::recv_from`]: struct.UdpSocket.html#method.recv_from +#[must_use] #[derive(Debug)] pub struct RecvFrom<'socket, 'buf> { socket: &'socket mut UdpSocket, diff --git a/src/task.rs b/src/task.rs index 5568cb68..59421bb2 100644 --- a/src/task.rs +++ b/src/task.rs @@ -45,6 +45,7 @@ where /// A handle that awaits the result of a [`spawn`]ed future. /// /// [`spawn`]: fn.spawn.html +#[must_use] #[derive(Debug)] pub struct JoinHandle { pub(crate) rx: futures::channel::oneshot::Receiver, From b53b00cd88d0b27cc866b2ca705ed60e5ebe6679 Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Sun, 12 May 2019 21:44:57 +0300 Subject: [PATCH 2/4] rustfmt applied --- examples/tcp-echo.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/tcp-echo.rs b/examples/tcp-echo.rs index b24a66cd..f1ae8d93 100644 --- a/examples/tcp-echo.rs +++ b/examples/tcp-echo.rs @@ -23,7 +23,8 @@ async fn main() -> std::io::Result<()> { let (reader, writer) = &mut stream.split(); reader.copy_into(writer).await?; Ok::<(), std::io::Error>(()) - }).await?; + }) + .await?; } Ok(()) } From 3f049c07230691ce6c994050613bcae27f1a6e9d Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Sun, 12 May 2019 22:16:11 +0300 Subject: [PATCH 3/4] added rusfmt.toml with unstable_features enabled --- rustfmt.toml | 1 + 1 file changed, 1 insertion(+) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..e1f312a6 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +unstable_features = true From f0cfe7a933aac58ba147d632ad49438cba19a41e Mon Sep 17 00:00:00 2001 From: ibaryshnikov Date: Mon, 13 May 2019 10:12:06 +0300 Subject: [PATCH 4/4] added text to must_use --- src/net/tcp.rs | 5 +++-- src/net/udp.rs | 4 ++-- src/task.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/net/tcp.rs b/src/net/tcp.rs index 4af95153..8d1cd436 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -217,7 +217,7 @@ impl AsyncWrite for TcpStream { /// /// [`TcpStream::connect`]: struct.TcpStream.html#method.connect /// [`TcpStream`]: struct.TcpStream.html -#[must_use] +#[must_use = "futures do nothing unless polled"] pub struct Connect { addrs: Option>>, last_err: Option, @@ -453,7 +453,7 @@ impl TcpListener { /// /// [`TcpStream::accept`]: struct.TcpStream.html#method.accept /// [`TcpStream`]: struct.TcpStream.html -#[must_use] +#[must_use = "futures do nothing unless polled"] #[derive(Debug)] pub struct Accept<'stream> { inner: Incoming<'stream>, @@ -481,6 +481,7 @@ impl<'stream> Future for Accept<'stream> { /// [`incoming`]: struct.TcpListener.html#method.incoming /// [`accept`]: struct.TcpStream.html#method.accept /// [`TcpListener`]: struct.TcpStream.html +#[must_use = "streams do nothing unless polled"] #[derive(Debug)] pub struct Incoming<'listener> { inner: &'listener mut TcpListener, diff --git a/src/net/udp.rs b/src/net/udp.rs index c6b5cd2c..3c5f92a6 100644 --- a/src/net/udp.rs +++ b/src/net/udp.rs @@ -358,7 +358,7 @@ impl UdpSocket { /// On success, returns the number of bytes written. /// /// [`UdpSocket::send_to`]: struct.UdpSocket.html#method.send_to -#[must_use] +#[must_use = "futures do nothing unless polled"] #[derive(Debug)] pub struct SendTo<'socket, 'buf> { /// The open socket we use to send the message from. @@ -393,7 +393,7 @@ impl<'socket, 'buf> Future for SendTo<'socket, 'buf> { /// On success, returns the number of bytes read and the origin. /// /// [`UdpSocket::recv_from`]: struct.UdpSocket.html#method.recv_from -#[must_use] +#[must_use = "futures do nothing unless polled"] #[derive(Debug)] pub struct RecvFrom<'socket, 'buf> { socket: &'socket mut UdpSocket, diff --git a/src/task.rs b/src/task.rs index 59421bb2..83c9a38d 100644 --- a/src/task.rs +++ b/src/task.rs @@ -45,7 +45,7 @@ where /// A handle that awaits the result of a [`spawn`]ed future. /// /// [`spawn`]: fn.spawn.html -#[must_use] +#[must_use = "futures do nothing unless polled"] #[derive(Debug)] pub struct JoinHandle { pub(crate) rx: futures::channel::oneshot::Receiver,