Skip to content
This repository was archived by the owner on Oct 30, 2019. It is now read-only.

Commit 51e45c6

Browse files
ibaryshnikovyoshuawuyts
authored andcommitted
added #[must_use] for impl Future structs (#31)
* added #[must_use] for impl Future structs * rustfmt applied * added rusfmt.toml with unstable_features enabled * added text to must_use
1 parent a0af792 commit 51e45c6

File tree

6 files changed

+10
-2
lines changed

6 files changed

+10
-2
lines changed

examples/guessing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async fn main() -> Result<(), failure::Error> {
6363

6464
let mut incoming = listener.incoming();
6565
while let Some(stream) = incoming.next().await {
66-
runtime::spawn(play(stream?));
66+
runtime::spawn(play(stream?)).await?;
6767
}
6868
Ok(())
6969
}

examples/tcp-echo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ async fn main() -> std::io::Result<()> {
2323
let (reader, writer) = &mut stream.split();
2424
reader.copy_into(writer).await?;
2525
Ok::<(), std::io::Error>(())
26-
});
26+
})
27+
.await?;
2728
}
2829
Ok(())
2930
}

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unstable_features = true

src/net/tcp.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ impl AsyncWrite for TcpStream {
217217
///
218218
/// [`TcpStream::connect`]: struct.TcpStream.html#method.connect
219219
/// [`TcpStream`]: struct.TcpStream.html
220+
#[must_use = "futures do nothing unless polled"]
220221
pub struct Connect {
221222
addrs: Option<io::Result<VecDeque<SocketAddr>>>,
222223
last_err: Option<io::Error>,
@@ -452,6 +453,7 @@ impl TcpListener {
452453
///
453454
/// [`TcpStream::accept`]: struct.TcpStream.html#method.accept
454455
/// [`TcpStream`]: struct.TcpStream.html
456+
#[must_use = "futures do nothing unless polled"]
455457
#[derive(Debug)]
456458
pub struct Accept<'stream> {
457459
inner: Incoming<'stream>,
@@ -479,6 +481,7 @@ impl<'stream> Future for Accept<'stream> {
479481
/// [`incoming`]: struct.TcpListener.html#method.incoming
480482
/// [`accept`]: struct.TcpStream.html#method.accept
481483
/// [`TcpListener`]: struct.TcpStream.html
484+
#[must_use = "streams do nothing unless polled"]
482485
#[derive(Debug)]
483486
pub struct Incoming<'listener> {
484487
inner: &'listener mut TcpListener,

src/net/udp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ impl UdpSocket {
358358
/// On success, returns the number of bytes written.
359359
///
360360
/// [`UdpSocket::send_to`]: struct.UdpSocket.html#method.send_to
361+
#[must_use = "futures do nothing unless polled"]
361362
#[derive(Debug)]
362363
pub struct SendTo<'socket, 'buf> {
363364
/// The open socket we use to send the message from.
@@ -392,6 +393,7 @@ impl<'socket, 'buf> Future for SendTo<'socket, 'buf> {
392393
/// On success, returns the number of bytes read and the origin.
393394
///
394395
/// [`UdpSocket::recv_from`]: struct.UdpSocket.html#method.recv_from
396+
#[must_use = "futures do nothing unless polled"]
395397
#[derive(Debug)]
396398
pub struct RecvFrom<'socket, 'buf> {
397399
socket: &'socket mut UdpSocket,

src/task.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ where
4545
/// A handle that awaits the result of a [`spawn`]ed future.
4646
///
4747
/// [`spawn`]: fn.spawn.html
48+
#[must_use = "futures do nothing unless polled"]
4849
#[derive(Debug)]
4950
pub struct JoinHandle<T> {
5051
pub(crate) rx: futures::channel::oneshot::Receiver<T>,

0 commit comments

Comments
 (0)