From b4fa47bd09f8eb3925d2416b429f2c238855e731 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Wed, 25 Oct 2017 17:57:25 -0700 Subject: [PATCH 1/3] Set Future types as must_use --- src/io/copy.rs | 1 + src/io/flush.rs | 1 + src/io/read.rs | 1 + src/io/read_exact.rs | 1 + src/io/read_to_end.rs | 1 + src/io/read_until.rs | 1 + src/io/write_all.rs | 1 + src/net/tcp.rs | 2 ++ src/net/udp/mod.rs | 2 ++ src/reactor/timeout.rs | 1 + 10 files changed, 12 insertions(+) diff --git a/src/io/copy.rs b/src/io/copy.rs index fa5677e04..d5f5c34d6 100644 --- a/src/io/copy.rs +++ b/src/io/copy.rs @@ -8,6 +8,7 @@ use futures::{Future, Poll}; /// bytes copied or an error if one happens. /// /// [`copy`]: fn.copy.html +#[must_use = "futures do nothing unless polled"] pub struct Copy { reader: R, read_done: bool, diff --git a/src/io/flush.rs b/src/io/flush.rs index f65164c08..5585e51b9 100644 --- a/src/io/flush.rs +++ b/src/io/flush.rs @@ -9,6 +9,7 @@ use futures::{Poll, Future, Async}; /// Created by the [`flush`] function. /// /// [`flush`]: fn.flush.html +#[must_use = "futures do nothing unless polled"] pub struct Flush { a: Option, } diff --git a/src/io/read.rs b/src/io/read.rs index 51bf9667f..f81007e9c 100644 --- a/src/io/read.rs +++ b/src/io/read.rs @@ -26,6 +26,7 @@ pub fn read(rd: R, buf: T) -> Read /// a buffer. /// /// Created by the [`read`] function. +#[must_use = "futures do nothing unless polled"] pub struct Read { state: State, } diff --git a/src/io/read_exact.rs b/src/io/read_exact.rs index bb0cea135..f4c51d542 100644 --- a/src/io/read_exact.rs +++ b/src/io/read_exact.rs @@ -9,6 +9,7 @@ use futures::{Poll, Future}; /// Created by the [`read_exact`] function. /// /// [`read_exact`]: fn.read_exact.html +#[must_use = "futures do nothing unless polled"] pub struct ReadExact { state: State, } diff --git a/src/io/read_to_end.rs b/src/io/read_to_end.rs index 63d5a82a5..e1b792d2b 100644 --- a/src/io/read_to_end.rs +++ b/src/io/read_to_end.rs @@ -9,6 +9,7 @@ use futures::{Poll, Future}; /// Created by the [`read_to_end`] function. /// /// [`read_to_end`]: fn.read_to_end.html +#[must_use = "futures do nothing unless polled"] pub struct ReadToEnd { state: State, } diff --git a/src/io/read_until.rs b/src/io/read_until.rs index 4e275cdc5..4263c5f12 100644 --- a/src/io/read_until.rs +++ b/src/io/read_until.rs @@ -9,6 +9,7 @@ use futures::{Poll, Future}; /// Created by the [`read_until`] function. /// /// [`read_until`]: fn.read_until.html +#[must_use = "futures do nothing unless polled"] pub struct ReadUntil { state: State, } diff --git a/src/io/write_all.rs b/src/io/write_all.rs index 949db4750..8916be662 100644 --- a/src/io/write_all.rs +++ b/src/io/write_all.rs @@ -8,6 +8,7 @@ use futures::{Poll, Future}; /// This is created by the [`write_all`] top-level method. /// /// [`write_all`]: fn.write_all.html +#[must_use = "futures do nothing unless polled"] pub struct WriteAll { state: State, } diff --git a/src/net/tcp.rs b/src/net/tcp.rs index e94f6fe5c..e1a680389 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -235,10 +235,12 @@ pub struct TcpStream { /// Future returned by `TcpStream::connect` which will resolve to a `TcpStream` /// when the stream is connected. +#[must_use = "futures do nothing unless polled"] pub struct TcpStreamNew { inner: TcpStreamNewState, } +#[must_use = "futures do nothing unless polled"] enum TcpStreamNewState { Waiting(TcpStream), Error(io::Error), diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index ad14fe981..36c006516 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -394,6 +394,7 @@ impl fmt::Debug for UdpSocket { /// A future used to write the entire contents of some data to a UDP socket. /// /// This is created by the `UdpSocket::send_dgram` method. +#[must_use = "futures do nothing unless polled"] pub struct SendDgram { state: SendState, } @@ -441,6 +442,7 @@ impl Future for SendDgram /// A future used to receive a datagram from a UDP socket. /// /// This is created by the `UdpSocket::recv_dgram` method. +#[must_use = "futures do nothing unless polled"] pub struct RecvDgram { state: RecvState, } diff --git a/src/reactor/timeout.rs b/src/reactor/timeout.rs index 5c96e5b0e..b4e19180e 100644 --- a/src/reactor/timeout.rs +++ b/src/reactor/timeout.rs @@ -18,6 +18,7 @@ use reactor::timeout_token::TimeoutToken; /// Note that timeouts are not intended for high resolution timers, but rather /// they will likely fire some granularity after the exact instant that they're /// otherwise indicated to fire at. +#[must_use = "futures do nothing unless polled"] #[derive(Debug)] pub struct Timeout { token: TimeoutToken, From bd9a07f3ad7cd16fba3c4dd8258a991a88c7f82d Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Wed, 25 Oct 2017 18:02:14 -0700 Subject: [PATCH 2/3] Set Stream types as must_use --- src/channel.rs | 1 + src/io/frame.rs | 1 + src/net/tcp.rs | 1 + src/reactor/interval.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/src/channel.rs b/src/channel.rs index 6251afb49..85060e52b 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -37,6 +37,7 @@ pub struct Sender { /// `Stream` trait to represent received messages. /// /// [`channel`]: fn.channel.html +#[must_use = "streams do nothing unless polled"] pub struct Receiver { rx: PollEvented>, } diff --git a/src/io/frame.rs b/src/io/frame.rs index 821dc3cfb..151648ac2 100644 --- a/src/io/frame.rs +++ b/src/io/frame.rs @@ -310,6 +310,7 @@ pub trait Codec { /// the `Codec` trait to encode and decode frames. /// /// You can acquire a `Framed` instance by using the `Io::framed` adapter. +#[must_use = "streams do nothing unless polled"] pub struct Framed { upstream: T, codec: C, diff --git a/src/net/tcp.rs b/src/net/tcp.rs index e1a680389..7cd7a1458 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -25,6 +25,7 @@ pub struct TcpListener { /// Stream returned by the `TcpListener::incoming` function representing the /// stream of sockets received from a listener. +#[must_use = "streams do nothing unless polled"] pub struct Incoming { inner: TcpListener, } diff --git a/src/reactor/interval.rs b/src/reactor/interval.rs index 647ea45bf..429be6c82 100644 --- a/src/reactor/interval.rs +++ b/src/reactor/interval.rs @@ -21,6 +21,7 @@ use reactor::timeout_token::TimeoutToken; /// Note that timeouts are not intended for high resolution timers, but rather /// they will likely fire some granularity after the exact instant that they're /// otherwise indicated to fire at. +#[must_use = "streams do nothing unless polled"] pub struct Interval { token: TimeoutToken, next: Instant, From 762406102161029b72874195939751a91c0c6186 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Wed, 25 Oct 2017 18:03:31 -0700 Subject: [PATCH 3/3] Set Sink types as must_use --- src/channel.rs | 1 + src/net/udp/frame.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/channel.rs b/src/channel.rs index 85060e52b..e9e023867 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -23,6 +23,7 @@ use reactor::{Handle, PollEvented}; /// This type is created by the [`channel`] function. /// /// [`channel`]: fn.channel.html +#[must_use = "sinks do nothing unless polled"] pub struct Sender { tx: channel::Sender, } diff --git a/src/net/udp/frame.rs b/src/net/udp/frame.rs index 1bb5deed6..5ae41b738 100644 --- a/src/net/udp/frame.rs +++ b/src/net/udp/frame.rs @@ -55,6 +55,7 @@ pub trait UdpCodec { /// /// You can acquire a `UdpFramed` instance by using the `UdpSocket::framed` /// adapter. +#[must_use = "sinks do nothing unless polled"] pub struct UdpFramed { socket: UdpSocket, codec: C,