From b14e189e44d6588ca4437ecbc2ca97ab7dedd925 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 16 Jul 2019 05:28:56 +0900 Subject: [PATCH] add #[must_use] to more futures and streams (#1309) --- tokio-fs/src/create_dir.rs | 1 + tokio-fs/src/create_dir_all.rs | 1 + tokio-fs/src/file/clone.rs | 1 + tokio-fs/src/file/create.rs | 1 + tokio-fs/src/file/metadata.rs | 1 + tokio-fs/src/file/open.rs | 1 + tokio-fs/src/file/seek.rs | 1 + tokio-fs/src/hard_link.rs | 1 + tokio-fs/src/metadata.rs | 1 + tokio-fs/src/read.rs | 1 + tokio-fs/src/read_dir.rs | 2 ++ tokio-fs/src/read_link.rs | 1 + tokio-fs/src/remove_dir.rs | 1 + tokio-fs/src/remove_file.rs | 1 + tokio-fs/src/rename.rs | 1 + tokio-fs/src/set_permissions.rs | 1 + tokio-fs/src/symlink_metadata.rs | 1 + tokio-fs/src/write.rs | 1 + tokio-tcp/src/stream.rs | 2 +- tokio-timer/src/timeout.rs | 2 +- tokio-udp/src/recv.rs | 2 +- tokio-udp/src/recv_from.rs | 2 +- tokio-udp/src/send.rs | 2 +- tokio-udp/src/send_to.rs | 2 +- tokio-uds/src/listener.rs | 2 +- tokio-uds/src/recv.rs | 2 +- tokio-uds/src/recv_from.rs | 2 +- tokio-uds/src/send.rs | 2 +- tokio-uds/src/send_to.rs | 2 +- tokio-uds/src/stream.rs | 2 +- tokio/src/io/copy.rs | 1 + tokio/src/io/read.rs | 1 + tokio/src/io/read_exact.rs | 1 + tokio/src/io/write.rs | 1 + 34 files changed, 35 insertions(+), 12 deletions(-) diff --git a/tokio-fs/src/create_dir.rs b/tokio-fs/src/create_dir.rs index ac784075f..f691a2b9a 100644 --- a/tokio-fs/src/create_dir.rs +++ b/tokio-fs/src/create_dir.rs @@ -17,6 +17,7 @@ pub fn create_dir>(path: P) -> CreateDirFuture

{ /// Future returned by `create_dir`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct CreateDirFuture

where P: AsRef, diff --git a/tokio-fs/src/create_dir_all.rs b/tokio-fs/src/create_dir_all.rs index 914c0b177..d9a84eb25 100644 --- a/tokio-fs/src/create_dir_all.rs +++ b/tokio-fs/src/create_dir_all.rs @@ -18,6 +18,7 @@ pub fn create_dir_all>(path: P) -> CreateDirAllFuture

{ /// Future returned by `create_dir_all`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct CreateDirAllFuture

where P: AsRef, diff --git a/tokio-fs/src/file/clone.rs b/tokio-fs/src/file/clone.rs index 24a443069..899f3346e 100644 --- a/tokio-fs/src/file/clone.rs +++ b/tokio-fs/src/file/clone.rs @@ -13,6 +13,7 @@ use std::task::Poll; /// /// Will panic if polled after returning an item or error. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct CloneFuture { file: Option, } diff --git a/tokio-fs/src/file/create.rs b/tokio-fs/src/file/create.rs index bc4661cb8..41ca554fa 100644 --- a/tokio-fs/src/file/create.rs +++ b/tokio-fs/src/file/create.rs @@ -8,6 +8,7 @@ use std::task::Context; use std::task::Poll; /// Future returned by `File::create` and resolves to a `File` instance. +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct CreateFuture

{ path: P, diff --git a/tokio-fs/src/file/metadata.rs b/tokio-fs/src/file/metadata.rs index a5aa4683b..67be837a4 100644 --- a/tokio-fs/src/file/metadata.rs +++ b/tokio-fs/src/file/metadata.rs @@ -11,6 +11,7 @@ const POLL_AFTER_RESOLVE: &str = "Cannot poll MetadataFuture after it resolves"; /// Future returned by `File::metadata` and resolves to a `(File, Metadata)` instance. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct MetadataFuture { file: Option, } diff --git a/tokio-fs/src/file/open.rs b/tokio-fs/src/file/open.rs index 5f7915eeb..c25c2e1fb 100644 --- a/tokio-fs/src/file/open.rs +++ b/tokio-fs/src/file/open.rs @@ -9,6 +9,7 @@ use std::task::Poll; /// Future returned by `File::open` and resolves to a `File` instance. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct OpenFuture { options: StdOpenOptions, path: P, diff --git a/tokio-fs/src/file/seek.rs b/tokio-fs/src/file/seek.rs index be0d997df..18ee43294 100644 --- a/tokio-fs/src/file/seek.rs +++ b/tokio-fs/src/file/seek.rs @@ -7,6 +7,7 @@ use std::task::Poll; /// Future returned by `File::seek`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct SeekFuture { inner: Option, pos: io::SeekFrom, diff --git a/tokio-fs/src/hard_link.rs b/tokio-fs/src/hard_link.rs index b4a023b3f..e18bac174 100644 --- a/tokio-fs/src/hard_link.rs +++ b/tokio-fs/src/hard_link.rs @@ -20,6 +20,7 @@ pub fn hard_link, Q: AsRef>(src: P, dst: Q) -> HardLinkFutu /// Future returned by `hard_link`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct HardLinkFuture where P: AsRef, diff --git a/tokio-fs/src/metadata.rs b/tokio-fs/src/metadata.rs index 11a252494..e54a5851a 100644 --- a/tokio-fs/src/metadata.rs +++ b/tokio-fs/src/metadata.rs @@ -17,6 +17,7 @@ where /// Future returned by `metadata`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct MetadataFuture

where P: AsRef + Send + 'static, diff --git a/tokio-fs/src/read.rs b/tokio-fs/src/read.rs index cfd0afe3f..a6e1a98f4 100644 --- a/tokio-fs/src/read.rs +++ b/tokio-fs/src/read.rs @@ -38,6 +38,7 @@ where /// A future used to open a file and read its entire contents into a buffer. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct ReadFile + Send + Unpin + 'static> { state: State

, } diff --git a/tokio-fs/src/read_dir.rs b/tokio-fs/src/read_dir.rs index 01e36d018..9585518b0 100644 --- a/tokio-fs/src/read_dir.rs +++ b/tokio-fs/src/read_dir.rs @@ -24,6 +24,7 @@ where /// Future returned by `read_dir`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct ReadDirFuture

where P: AsRef + Send + 'static, @@ -68,6 +69,7 @@ where /// [`Stream`]: ../futures/stream/trait.Stream.html /// [`Err`]: https://doc.rust-lang.org/std/result/enum.Result.html#variant.Err #[derive(Debug)] +#[must_use = "streams do nothing unless polled"] pub struct ReadDir(StdReadDir); impl Stream for ReadDir { diff --git a/tokio-fs/src/read_link.rs b/tokio-fs/src/read_link.rs index d5b9fe2d4..980f922eb 100644 --- a/tokio-fs/src/read_link.rs +++ b/tokio-fs/src/read_link.rs @@ -17,6 +17,7 @@ pub fn read_link>(path: P) -> ReadLinkFuture

{ /// Future returned by `read_link`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct ReadLinkFuture

where P: AsRef, diff --git a/tokio-fs/src/remove_dir.rs b/tokio-fs/src/remove_dir.rs index b0de35e16..3e666c681 100644 --- a/tokio-fs/src/remove_dir.rs +++ b/tokio-fs/src/remove_dir.rs @@ -17,6 +17,7 @@ pub fn remove_dir>(path: P) -> RemoveDirFuture

{ /// Future returned by `remove_dir`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct RemoveDirFuture

where P: AsRef, diff --git a/tokio-fs/src/remove_file.rs b/tokio-fs/src/remove_file.rs index ca8b80888..b09eae77d 100644 --- a/tokio-fs/src/remove_file.rs +++ b/tokio-fs/src/remove_file.rs @@ -21,6 +21,7 @@ pub fn remove_file>(path: P) -> RemoveFileFuture

{ /// Future returned by `remove_file`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct RemoveFileFuture

where P: AsRef, diff --git a/tokio-fs/src/rename.rs b/tokio-fs/src/rename.rs index 742ced04b..670a9c7d5 100644 --- a/tokio-fs/src/rename.rs +++ b/tokio-fs/src/rename.rs @@ -20,6 +20,7 @@ pub fn rename, Q: AsRef>(from: P, to: Q) -> RenameFuture where P: AsRef, diff --git a/tokio-fs/src/set_permissions.rs b/tokio-fs/src/set_permissions.rs index d5bdfd674..e91c33b88 100644 --- a/tokio-fs/src/set_permissions.rs +++ b/tokio-fs/src/set_permissions.rs @@ -17,6 +17,7 @@ pub fn set_permissions>(path: P, perm: fs::Permissions) -> SetPer /// Future returned by `set_permissions`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct SetPermissionsFuture

where P: AsRef, diff --git a/tokio-fs/src/symlink_metadata.rs b/tokio-fs/src/symlink_metadata.rs index cc4509590..0cae53c5e 100644 --- a/tokio-fs/src/symlink_metadata.rs +++ b/tokio-fs/src/symlink_metadata.rs @@ -21,6 +21,7 @@ where /// Future returned by `symlink_metadata`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct SymlinkMetadataFuture

where P: AsRef + Send + 'static, diff --git a/tokio-fs/src/write.rs b/tokio-fs/src/write.rs index 4b63984c8..d3d357ca3 100644 --- a/tokio-fs/src/write.rs +++ b/tokio-fs/src/write.rs @@ -41,6 +41,7 @@ where /// A future used to open a file for writing and write the entire contents /// of some data to it. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct WriteFile + Send + Unpin + 'static, C: AsRef<[u8]> + Unpin> { state: State, } diff --git a/tokio-tcp/src/stream.rs b/tokio-tcp/src/stream.rs index e621f8708..df4de87e0 100644 --- a/tokio-tcp/src/stream.rs +++ b/tokio-tcp/src/stream.rs @@ -46,7 +46,7 @@ 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"] +#[must_use = "futures do nothing unless you `.await` or poll them"] struct ConnectFuture { inner: ConnectFutureState, } diff --git a/tokio-timer/src/timeout.rs b/tokio-timer/src/timeout.rs index 18068778b..9fe0cd557 100644 --- a/tokio-timer/src/timeout.rs +++ b/tokio-timer/src/timeout.rs @@ -65,7 +65,7 @@ use std::time::{Duration, Instant}; /// /// [`Error`]: struct.Error.html /// [`Timeout::into_inner`]: struct.Timeout.html#method.into_iter -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct Timeout { value: T, diff --git a/tokio-udp/src/recv.rs b/tokio-udp/src/recv.rs index 1c9075436..47331d3ab 100644 --- a/tokio-udp/src/recv.rs +++ b/tokio-udp/src/recv.rs @@ -7,7 +7,7 @@ use std::task::{Context, Poll}; /// A future that receives a datagram from the connected address. /// /// This `struct` is created by [`recv`](super::UdpSocket::recv). -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct Recv<'a, 'b> { socket: &'a UdpSocket, diff --git a/tokio-udp/src/recv_from.rs b/tokio-udp/src/recv_from.rs index f4d934265..04bef680a 100644 --- a/tokio-udp/src/recv_from.rs +++ b/tokio-udp/src/recv_from.rs @@ -8,7 +8,7 @@ use std::task::{Context, Poll}; /// A future that receives a datagram. /// /// This `struct` is created by [`recv_from`](super::UdpSocket::recv_from). -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct RecvFrom<'a, 'b> { socket: &'a UdpSocket, diff --git a/tokio-udp/src/send.rs b/tokio-udp/src/send.rs index 6debe4e3e..8fd1007f4 100644 --- a/tokio-udp/src/send.rs +++ b/tokio-udp/src/send.rs @@ -7,7 +7,7 @@ use std::task::{Context, Poll}; /// A future that sends a datagram to the connected address. /// /// This `struct` is created by [`send`](super::UdpSocket::send). -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct Send<'a, 'b> { socket: &'a UdpSocket, diff --git a/tokio-udp/src/send_to.rs b/tokio-udp/src/send_to.rs index fa1ab7637..b7f241214 100644 --- a/tokio-udp/src/send_to.rs +++ b/tokio-udp/src/send_to.rs @@ -8,7 +8,7 @@ use std::task::{Context, Poll}; /// A future that sends a datagram to a given address. /// /// This `struct` is created by [`send_to`](super::UdpSocket::send_to). -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct SendTo<'a, 'b> { socket: &'a UdpSocket, diff --git a/tokio-uds/src/listener.rs b/tokio-uds/src/listener.rs index 17c503055..4769516ad 100644 --- a/tokio-uds/src/listener.rs +++ b/tokio-uds/src/listener.rs @@ -168,7 +168,7 @@ impl AsRawFd for UnixListener { } /// Future type returned by [`UnixListener::accept`]. -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct Accept<'a> { listener: &'a mut UnixListener, diff --git a/tokio-uds/src/recv.rs b/tokio-uds/src/recv.rs index 41e7b1381..04e6060fd 100644 --- a/tokio-uds/src/recv.rs +++ b/tokio-uds/src/recv.rs @@ -7,7 +7,7 @@ use std::task::{Context, Poll}; /// A future that receives a datagram from the connected address. /// /// This `struct` is created by [`recv`](crate::UnixDatagram::recv). -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct Recv<'a, 'b> { socket: &'a mut UnixDatagram, diff --git a/tokio-uds/src/recv_from.rs b/tokio-uds/src/recv_from.rs index 873ae5963..c2cb34bff 100644 --- a/tokio-uds/src/recv_from.rs +++ b/tokio-uds/src/recv_from.rs @@ -8,7 +8,7 @@ use std::task::{Context, Poll}; /// A future that receives a datagram. /// /// This `struct` is created by [`recv_from`](crate::UnixDatagram::recv_from). -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct RecvFrom<'a, 'b> { socket: &'a UnixDatagram, diff --git a/tokio-uds/src/send.rs b/tokio-uds/src/send.rs index e03f785af..2abc5adeb 100644 --- a/tokio-uds/src/send.rs +++ b/tokio-uds/src/send.rs @@ -7,7 +7,7 @@ use std::task::{Context, Poll}; /// A future that sends a datagram to the connected address. /// /// This `struct` is created by [`send`](crate::UnixDatagram::send). -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct Send<'a, 'b> { socket: &'a UnixDatagram, diff --git a/tokio-uds/src/send_to.rs b/tokio-uds/src/send_to.rs index 014b74ff6..5aa83e3ec 100644 --- a/tokio-uds/src/send_to.rs +++ b/tokio-uds/src/send_to.rs @@ -8,7 +8,7 @@ use std::task::{Context, Poll}; /// A future that sends a datagram to a given address. /// /// This `struct` is created by [`send_to`](crate::UnixDatagram::send_to). -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] #[derive(Debug)] pub struct SendTo<'a, 'b, P> { socket: &'a UnixDatagram, diff --git a/tokio-uds/src/stream.rs b/tokio-uds/src/stream.rs index 7d13245f1..5c1eef74c 100644 --- a/tokio-uds/src/stream.rs +++ b/tokio-uds/src/stream.rs @@ -29,7 +29,7 @@ pub struct UnixStream { /// Future returned by `UnixStream::connect` which will resolve to a /// `UnixStream` when the stream is connected. #[derive(Debug)] -#[must_use = "futures do nothing unless polled"] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct ConnectFuture { stream: Option>, } diff --git a/tokio/src/io/copy.rs b/tokio/src/io/copy.rs index a324cbf8c..fe1ac052a 100644 --- a/tokio/src/io/copy.rs +++ b/tokio/src/io/copy.rs @@ -6,6 +6,7 @@ use std::task::{Context, Poll}; use tokio_io::{AsyncRead, AsyncWrite}; #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Copy<'a, R: ?Sized, W: ?Sized> { reader: &'a mut R, read_done: bool, diff --git a/tokio/src/io/read.rs b/tokio/src/io/read.rs index 320c5edd8..acfcae430 100644 --- a/tokio/src/io/read.rs +++ b/tokio/src/io/read.rs @@ -22,6 +22,7 @@ where /// /// Created by the [`read`] function. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Read<'a, R: ?Sized> { reader: &'a mut R, buf: &'a mut [u8], diff --git a/tokio/src/io/read_exact.rs b/tokio/src/io/read_exact.rs index 82b953629..7db5acfdf 100644 --- a/tokio/src/io/read_exact.rs +++ b/tokio/src/io/read_exact.rs @@ -28,6 +28,7 @@ where /// /// On success the number of bytes is returned #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct ReadExact<'a, A: ?Sized> { reader: &'a mut A, buf: &'a mut [u8], diff --git a/tokio/src/io/write.rs b/tokio/src/io/write.rs index 2ccc61b5b..d52885272 100644 --- a/tokio/src/io/write.rs +++ b/tokio/src/io/write.rs @@ -7,6 +7,7 @@ use tokio_io::AsyncWrite; /// A future to write some of the buffer to an `AsyncWrite`. #[derive(Debug)] +#[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Write<'a, W: ?Sized> { writer: &'a mut W, buf: &'a [u8],