add #[must_use] to more futures and streams (#1309)

This commit is contained in:
Taiki Endo 2019-07-16 05:28:56 +09:00 committed by Carl Lerche
parent 2dde2b448f
commit b14e189e44
34 changed files with 35 additions and 12 deletions

View File

@ -17,6 +17,7 @@ pub fn create_dir<P: AsRef<Path>>(path: P) -> CreateDirFuture<P> {
/// Future returned by `create_dir`. /// Future returned by `create_dir`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct CreateDirFuture<P> pub struct CreateDirFuture<P>
where where
P: AsRef<Path>, P: AsRef<Path>,

View File

@ -18,6 +18,7 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) -> CreateDirAllFuture<P> {
/// Future returned by `create_dir_all`. /// Future returned by `create_dir_all`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct CreateDirAllFuture<P> pub struct CreateDirAllFuture<P>
where where
P: AsRef<Path>, P: AsRef<Path>,

View File

@ -13,6 +13,7 @@ use std::task::Poll;
/// ///
/// Will panic if polled after returning an item or error. /// Will panic if polled after returning an item or error.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct CloneFuture { pub struct CloneFuture {
file: Option<File>, file: Option<File>,
} }

View File

@ -8,6 +8,7 @@ use std::task::Context;
use std::task::Poll; use std::task::Poll;
/// Future returned by `File::create` and resolves to a `File` instance. /// Future returned by `File::create` and resolves to a `File` instance.
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[derive(Debug)] #[derive(Debug)]
pub struct CreateFuture<P> { pub struct CreateFuture<P> {
path: P, path: P,

View File

@ -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. /// Future returned by `File::metadata` and resolves to a `(File, Metadata)` instance.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct MetadataFuture { pub struct MetadataFuture {
file: Option<File>, file: Option<File>,
} }

View File

@ -9,6 +9,7 @@ use std::task::Poll;
/// Future returned by `File::open` and resolves to a `File` instance. /// Future returned by `File::open` and resolves to a `File` instance.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct OpenFuture<P: Unpin> { pub struct OpenFuture<P: Unpin> {
options: StdOpenOptions, options: StdOpenOptions,
path: P, path: P,

View File

@ -7,6 +7,7 @@ use std::task::Poll;
/// Future returned by `File::seek`. /// Future returned by `File::seek`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct SeekFuture { pub struct SeekFuture {
inner: Option<File>, inner: Option<File>,
pos: io::SeekFrom, pos: io::SeekFrom,

View File

@ -20,6 +20,7 @@ pub fn hard_link<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> HardLinkFutu
/// Future returned by `hard_link`. /// Future returned by `hard_link`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct HardLinkFuture<P, Q> pub struct HardLinkFuture<P, Q>
where where
P: AsRef<Path>, P: AsRef<Path>,

View File

@ -17,6 +17,7 @@ where
/// Future returned by `metadata`. /// Future returned by `metadata`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct MetadataFuture<P> pub struct MetadataFuture<P>
where where
P: AsRef<Path> + Send + 'static, P: AsRef<Path> + Send + 'static,

View File

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

View File

@ -24,6 +24,7 @@ where
/// Future returned by `read_dir`. /// Future returned by `read_dir`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct ReadDirFuture<P> pub struct ReadDirFuture<P>
where where
P: AsRef<Path> + Send + 'static, P: AsRef<Path> + Send + 'static,
@ -68,6 +69,7 @@ where
/// [`Stream`]: ../futures/stream/trait.Stream.html /// [`Stream`]: ../futures/stream/trait.Stream.html
/// [`Err`]: https://doc.rust-lang.org/std/result/enum.Result.html#variant.Err /// [`Err`]: https://doc.rust-lang.org/std/result/enum.Result.html#variant.Err
#[derive(Debug)] #[derive(Debug)]
#[must_use = "streams do nothing unless polled"]
pub struct ReadDir(StdReadDir); pub struct ReadDir(StdReadDir);
impl Stream for ReadDir { impl Stream for ReadDir {

View File

@ -17,6 +17,7 @@ pub fn read_link<P: AsRef<Path>>(path: P) -> ReadLinkFuture<P> {
/// Future returned by `read_link`. /// Future returned by `read_link`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct ReadLinkFuture<P> pub struct ReadLinkFuture<P>
where where
P: AsRef<Path>, P: AsRef<Path>,

View File

@ -17,6 +17,7 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> RemoveDirFuture<P> {
/// Future returned by `remove_dir`. /// Future returned by `remove_dir`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct RemoveDirFuture<P> pub struct RemoveDirFuture<P>
where where
P: AsRef<Path>, P: AsRef<Path>,

View File

@ -21,6 +21,7 @@ pub fn remove_file<P: AsRef<Path>>(path: P) -> RemoveFileFuture<P> {
/// Future returned by `remove_file`. /// Future returned by `remove_file`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct RemoveFileFuture<P> pub struct RemoveFileFuture<P>
where where
P: AsRef<Path>, P: AsRef<Path>,

View File

@ -20,6 +20,7 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> RenameFuture<P,
/// Future returned by `rename`. /// Future returned by `rename`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct RenameFuture<P, Q> pub struct RenameFuture<P, Q>
where where
P: AsRef<Path>, P: AsRef<Path>,

View File

@ -17,6 +17,7 @@ pub fn set_permissions<P: AsRef<Path>>(path: P, perm: fs::Permissions) -> SetPer
/// Future returned by `set_permissions`. /// Future returned by `set_permissions`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct SetPermissionsFuture<P> pub struct SetPermissionsFuture<P>
where where
P: AsRef<Path>, P: AsRef<Path>,

View File

@ -21,6 +21,7 @@ where
/// Future returned by `symlink_metadata`. /// Future returned by `symlink_metadata`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct SymlinkMetadataFuture<P> pub struct SymlinkMetadataFuture<P>
where where
P: AsRef<Path> + Send + 'static, P: AsRef<Path> + Send + 'static,

View File

@ -41,6 +41,7 @@ where
/// A future used to open a file for writing and write the entire contents /// A future used to open a file for writing and write the entire contents
/// of some data to it. /// of some data to it.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct WriteFile<P: AsRef<Path> + Send + Unpin + 'static, C: AsRef<[u8]> + Unpin> { pub struct WriteFile<P: AsRef<Path> + Send + Unpin + 'static, C: AsRef<[u8]> + Unpin> {
state: State<P, C>, state: State<P, C>,
} }

View File

@ -46,7 +46,7 @@ pub struct TcpStream {
/// Future returned by `TcpStream::connect` which will resolve to a `TcpStream` /// Future returned by `TcpStream::connect` which will resolve to a `TcpStream`
/// when the stream is connected. /// 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 { struct ConnectFuture {
inner: ConnectFutureState, inner: ConnectFutureState,
} }

View File

@ -65,7 +65,7 @@ use std::time::{Duration, Instant};
/// ///
/// [`Error`]: struct.Error.html /// [`Error`]: struct.Error.html
/// [`Timeout::into_inner`]: struct.Timeout.html#method.into_iter /// [`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)] #[derive(Debug)]
pub struct Timeout<T> { pub struct Timeout<T> {
value: T, value: T,

View File

@ -7,7 +7,7 @@ use std::task::{Context, Poll};
/// A future that receives a datagram from the connected address. /// A future that receives a datagram from the connected address.
/// ///
/// This `struct` is created by [`recv`](super::UdpSocket::recv). /// 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)] #[derive(Debug)]
pub struct Recv<'a, 'b> { pub struct Recv<'a, 'b> {
socket: &'a UdpSocket, socket: &'a UdpSocket,

View File

@ -8,7 +8,7 @@ use std::task::{Context, Poll};
/// A future that receives a datagram. /// A future that receives a datagram.
/// ///
/// This `struct` is created by [`recv_from`](super::UdpSocket::recv_from). /// 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)] #[derive(Debug)]
pub struct RecvFrom<'a, 'b> { pub struct RecvFrom<'a, 'b> {
socket: &'a UdpSocket, socket: &'a UdpSocket,

View File

@ -7,7 +7,7 @@ use std::task::{Context, Poll};
/// A future that sends a datagram to the connected address. /// A future that sends a datagram to the connected address.
/// ///
/// This `struct` is created by [`send`](super::UdpSocket::send). /// 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)] #[derive(Debug)]
pub struct Send<'a, 'b> { pub struct Send<'a, 'b> {
socket: &'a UdpSocket, socket: &'a UdpSocket,

View File

@ -8,7 +8,7 @@ use std::task::{Context, Poll};
/// A future that sends a datagram to a given address. /// A future that sends a datagram to a given address.
/// ///
/// This `struct` is created by [`send_to`](super::UdpSocket::send_to). /// 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)] #[derive(Debug)]
pub struct SendTo<'a, 'b> { pub struct SendTo<'a, 'b> {
socket: &'a UdpSocket, socket: &'a UdpSocket,

View File

@ -168,7 +168,7 @@ impl AsRawFd for UnixListener {
} }
/// Future type returned by [`UnixListener::accept`]. /// 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)] #[derive(Debug)]
pub struct Accept<'a> { pub struct Accept<'a> {
listener: &'a mut UnixListener, listener: &'a mut UnixListener,

View File

@ -7,7 +7,7 @@ use std::task::{Context, Poll};
/// A future that receives a datagram from the connected address. /// A future that receives a datagram from the connected address.
/// ///
/// This `struct` is created by [`recv`](crate::UnixDatagram::recv). /// 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)] #[derive(Debug)]
pub struct Recv<'a, 'b> { pub struct Recv<'a, 'b> {
socket: &'a mut UnixDatagram, socket: &'a mut UnixDatagram,

View File

@ -8,7 +8,7 @@ use std::task::{Context, Poll};
/// A future that receives a datagram. /// A future that receives a datagram.
/// ///
/// This `struct` is created by [`recv_from`](crate::UnixDatagram::recv_from). /// 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)] #[derive(Debug)]
pub struct RecvFrom<'a, 'b> { pub struct RecvFrom<'a, 'b> {
socket: &'a UnixDatagram, socket: &'a UnixDatagram,

View File

@ -7,7 +7,7 @@ use std::task::{Context, Poll};
/// A future that sends a datagram to the connected address. /// A future that sends a datagram to the connected address.
/// ///
/// This `struct` is created by [`send`](crate::UnixDatagram::send). /// 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)] #[derive(Debug)]
pub struct Send<'a, 'b> { pub struct Send<'a, 'b> {
socket: &'a UnixDatagram, socket: &'a UnixDatagram,

View File

@ -8,7 +8,7 @@ use std::task::{Context, Poll};
/// A future that sends a datagram to a given address. /// A future that sends a datagram to a given address.
/// ///
/// This `struct` is created by [`send_to`](crate::UnixDatagram::send_to). /// 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)] #[derive(Debug)]
pub struct SendTo<'a, 'b, P> { pub struct SendTo<'a, 'b, P> {
socket: &'a UnixDatagram, socket: &'a UnixDatagram,

View File

@ -29,7 +29,7 @@ pub struct UnixStream {
/// Future returned by `UnixStream::connect` which will resolve to a /// Future returned by `UnixStream::connect` which will resolve to a
/// `UnixStream` when the stream is connected. /// `UnixStream` when the stream is connected.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless polled"] #[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct ConnectFuture { pub struct ConnectFuture {
stream: Option<io::Result<UnixStream>>, stream: Option<io::Result<UnixStream>>,
} }

View File

@ -6,6 +6,7 @@ use std::task::{Context, Poll};
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Copy<'a, R: ?Sized, W: ?Sized> { pub struct Copy<'a, R: ?Sized, W: ?Sized> {
reader: &'a mut R, reader: &'a mut R,
read_done: bool, read_done: bool,

View File

@ -22,6 +22,7 @@ where
/// ///
/// Created by the [`read`] function. /// Created by the [`read`] function.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Read<'a, R: ?Sized> { pub struct Read<'a, R: ?Sized> {
reader: &'a mut R, reader: &'a mut R,
buf: &'a mut [u8], buf: &'a mut [u8],

View File

@ -28,6 +28,7 @@ where
/// ///
/// On success the number of bytes is returned /// On success the number of bytes is returned
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct ReadExact<'a, A: ?Sized> { pub struct ReadExact<'a, A: ?Sized> {
reader: &'a mut A, reader: &'a mut A,
buf: &'a mut [u8], buf: &'a mut [u8],

View File

@ -7,6 +7,7 @@ use tokio_io::AsyncWrite;
/// A future to write some of the buffer to an `AsyncWrite`. /// A future to write some of the buffer to an `AsyncWrite`.
#[derive(Debug)] #[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Write<'a, W: ?Sized> { pub struct Write<'a, W: ?Sized> {
writer: &'a mut W, writer: &'a mut W,
buf: &'a [u8], buf: &'a [u8],