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`.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct CreateDirFuture<P>
where
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`.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct CreateDirAllFuture<P>
where
P: AsRef<Path>,

View File

@ -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<File>,
}

View File

@ -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<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.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct MetadataFuture {
file: Option<File>,
}

View File

@ -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<P: Unpin> {
options: StdOpenOptions,
path: P,

View File

@ -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<File>,
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`.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct HardLinkFuture<P, Q>
where
P: AsRef<Path>,

View File

@ -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<P>
where
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.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct ReadFile<P: AsRef<Path> + Send + Unpin + 'static> {
state: State<P>,
}

View File

@ -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<P>
where
P: AsRef<Path> + 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 {

View File

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

View File

@ -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<P>
where
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
/// of some data to it.
#[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> {
state: State<P, C>,
}

View File

@ -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,
}

View File

@ -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<T> {
value: T,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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<io::Result<UnixStream>>,
}

View File

@ -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,

View File

@ -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],

View File

@ -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],

View File

@ -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],