Skip to content

Commit bd8dafa

Browse files
taiki-ecramertj
authored andcommitted
Remove uses of try_ready! macro
1 parent ac76d10 commit bd8dafa

File tree

15 files changed

+34
-36
lines changed

15 files changed

+34
-36
lines changed

futures-util/src/io/copy_into.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<R, W> Future for CopyInto<'_, R, W>
4545
// If our buffer is empty, then we need to read some data to
4646
// continue.
4747
if this.pos == this.cap && !this.read_done {
48-
let n = try_ready!(Pin::new(&mut this.reader).poll_read(cx, &mut this.buf));
48+
let n = ready!(Pin::new(&mut this.reader).poll_read(cx, &mut this.buf))?;
4949
if n == 0 {
5050
this.read_done = true;
5151
} else {
@@ -56,7 +56,7 @@ impl<R, W> Future for CopyInto<'_, R, W>
5656

5757
// If our buffer has some data, let's write it out!
5858
while this.pos < this.cap {
59-
let i = try_ready!(Pin::new(&mut this.writer).poll_write(cx, &this.buf[this.pos..this.cap]));
59+
let i = ready!(Pin::new(&mut this.writer).poll_write(cx, &this.buf[this.pos..this.cap]))?;
6060
if i == 0 {
6161
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()))
6262
} else {
@@ -69,7 +69,7 @@ impl<R, W> Future for CopyInto<'_, R, W>
6969
// data and finish the transfer.
7070
// done with the entire transfer.
7171
if this.pos == this.cap && this.read_done {
72-
try_ready!(Pin::new(&mut this.writer).poll_flush(cx));
72+
ready!(Pin::new(&mut this.writer).poll_flush(cx))?;
7373
return Poll::Ready(Ok(this.amt));
7474
}
7575
}

futures-util/src/io/read_exact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<R: AsyncRead + ?Sized + Unpin> Future for ReadExact<'_, R> {
2626
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
2727
let this = &mut *self;
2828
while !this.buf.is_empty() {
29-
let n = try_ready!(Pin::new(&mut this.reader).poll_read(cx, this.buf));
29+
let n = ready!(Pin::new(&mut this.reader).poll_read(cx, this.buf))?;
3030
{
3131
let (_, rest) = mem::replace(&mut this.buf, &mut []).split_at_mut(n);
3232
this.buf = rest;

futures-util/src/io/read_until.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn read_until_internal<R: AsyncBufRead + ?Sized + Unpin>(
3131
) -> Poll<io::Result<usize>> {
3232
loop {
3333
let (done, used) = {
34-
let available = try_ready!(reader.as_mut().poll_fill_buf(cx));
34+
let available = ready!(reader.as_mut().poll_fill_buf(cx))?;
3535
if let Some(i) = memchr::memchr(byte, available) {
3636
buf.extend_from_slice(&available[..=i]);
3737
(true, i + 1)

futures-util/src/io/write_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteAll<'_, W> {
2626
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
2727
let this = &mut *self;
2828
while !this.buf.is_empty() {
29-
let n = try_ready!(Pin::new(&mut this.writer).poll_write(cx, this.buf));
29+
let n = ready!(Pin::new(&mut this.writer).poll_write(cx, this.buf))?;
3030
{
3131
let (_, rest) = mem::replace(&mut this.buf, &[]).split_at(n);
3232
this.buf = rest;

futures-util/src/sink/buffer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ impl<Si: Sink<Item>, Item> Buffer<Si, Item> {
5858
mut self: Pin<&mut Self>,
5959
cx: &mut Context<'_>,
6060
) -> Poll<Result<(), Si::SinkError>> {
61-
try_ready!(self.as_mut().sink().poll_ready(cx));
61+
ready!(self.as_mut().sink().poll_ready(cx))?;
6262
while let Some(item) = self.as_mut().buf().pop_front() {
6363
if let Err(e) = self.as_mut().sink().start_send(item) {
6464
return Poll::Ready(Err(e));
6565
}
6666
if !self.buf.is_empty() {
67-
try_ready!(self.as_mut().sink().poll_ready(cx));
67+
ready!(self.as_mut().sink().poll_ready(cx))?;
6868
}
6969
}
7070
Poll::Ready(Ok(()))
@@ -118,7 +118,7 @@ impl<Si: Sink<Item>, Item> Sink<Item> for Buffer<Si, Item> {
118118
mut self: Pin<&mut Self>,
119119
cx: &mut Context<'_>,
120120
) -> Poll<Result<(), Self::SinkError>> {
121-
try_ready!(self.as_mut().try_empty_buffer(cx));
121+
ready!(self.as_mut().try_empty_buffer(cx))?;
122122
debug_assert!(self.as_mut().buf().is_empty());
123123
self.as_mut().sink().poll_flush(cx)
124124
}
@@ -127,7 +127,7 @@ impl<Si: Sink<Item>, Item> Sink<Item> for Buffer<Si, Item> {
127127
mut self: Pin<&mut Self>,
128128
cx: &mut Context<'_>,
129129
) -> Poll<Result<(), Self::SinkError>> {
130-
try_ready!(self.as_mut().try_empty_buffer(cx));
130+
ready!(self.as_mut().try_empty_buffer(cx))?;
131131
debug_assert!(self.as_mut().buf().is_empty());
132132
self.as_mut().sink().poll_close(cx)
133133
}

futures-util/src/sink/send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<Si: Sink<Item> + Unpin + ?Sized, Item> Future for Send<'_, Si, Item> {
4949

5050
// we're done sending the item, but want to block on flushing the
5151
// sink
52-
try_ready!(Pin::new(&mut this.sink).poll_flush(cx));
52+
ready!(Pin::new(&mut this.sink).poll_flush(cx))?;
5353

5454
Poll::Ready(Ok(()))
5555
}

futures-util/src/sink/send_all.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,20 @@ where
7575
// If we've got an item buffered already, we need to write it to the
7676
// sink before we can do anything else
7777
if let Some(item) = this.buffered.take() {
78-
try_ready!(this.try_start_send(cx, item))
78+
ready!(this.try_start_send(cx, item))?
7979
}
8080

8181
loop {
8282
match this.stream.poll_next_unpin(cx) {
8383
Poll::Ready(Some(item)) => {
84-
try_ready!(this.try_start_send(cx, item))
84+
ready!(this.try_start_send(cx, item))?
8585
}
8686
Poll::Ready(None) => {
87-
try_ready!(Pin::new(&mut this.sink).poll_flush(cx));
87+
ready!(Pin::new(&mut this.sink).poll_flush(cx))?;
8888
return Poll::Ready(Ok(()))
8989
}
9090
Poll::Pending => {
91-
try_ready!(Pin::new(&mut this.sink).poll_flush(cx));
91+
ready!(Pin::new(&mut this.sink).poll_flush(cx))?;
9292
return Poll::Pending
9393
}
9494
}

futures-util/src/sink/with.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<Si, Item, U, Fut, F, E> With<Si, Item, U, Fut, F>
126126
) -> Poll<Result<(), E>> {
127127
let buffered = match self.as_mut().state().as_pin_mut() {
128128
State::Empty => return Poll::Ready(Ok(())),
129-
State::Process(fut) => Some(try_ready!(fut.poll(cx))),
129+
State::Process(fut) => Some(ready!(fut.poll(cx))?),
130130
State::Buffered(_) => None,
131131
};
132132
if let Some(buffered) = buffered {
@@ -168,17 +168,17 @@ impl<Si, Item, U, Fut, F, E> Sink<U> for With<Si, Item, U, Fut, F>
168168
mut self: Pin<&mut Self>,
169169
cx: &mut Context<'_>,
170170
) -> Poll<Result<(), Self::SinkError>> {
171-
try_ready!(self.as_mut().poll(cx));
172-
try_ready!(self.as_mut().sink().poll_flush(cx));
171+
ready!(self.as_mut().poll(cx))?;
172+
ready!(self.as_mut().sink().poll_flush(cx))?;
173173
Poll::Ready(Ok(()))
174174
}
175175

176176
fn poll_close(
177177
mut self: Pin<&mut Self>,
178178
cx: &mut Context<'_>,
179179
) -> Poll<Result<(), Self::SinkError>> {
180-
try_ready!(self.as_mut().poll(cx));
181-
try_ready!(self.as_mut().sink().poll_close(cx));
180+
ready!(self.as_mut().poll(cx))?;
181+
ready!(self.as_mut().sink().poll_close(cx))?;
182182
Poll::Ready(Ok(()))
183183
}
184184
}

futures-util/src/sink/with_flat_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ where
8181
let mut stream = unsafe { Pin::new_unchecked(stream) };
8282

8383
if buffer.is_some() {
84-
try_ready!(sink.as_mut().poll_ready(cx));
84+
ready!(sink.as_mut().poll_ready(cx))?;
8585
let item = buffer.take().unwrap();
86-
try_ready!(Poll::Ready(sink.as_mut().start_send(item)));
86+
ready!(Poll::Ready(sink.as_mut().start_send(item)))?;
8787
}
8888
if let Some(mut some_stream) = stream.as_mut().as_pin_mut() {
8989
while let Some(x) = ready!(some_stream.as_mut().poll_next(cx)) {
90-
let item = try_ready!(Poll::Ready(x));
90+
let item = ready!(Poll::Ready(x))?;
9191
match sink.as_mut().poll_ready(cx)? {
9292
Poll::Ready(()) => sink.as_mut().start_send(item)?,
9393
Poll::Pending => {

futures-util/src/stream/forward.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,21 @@ where
7373
// If we've got an item buffered already, we need to write it to the
7474
// sink before we can do anything else
7575
if let Some(item) = self.as_mut().buffered_item().take() {
76-
try_ready!(self.as_mut().try_start_send(cx, item));
76+
ready!(self.as_mut().try_start_send(cx, item))?;
7777
}
7878

7979
loop {
8080
match self.as_mut().stream().poll_next(cx) {
8181
Poll::Ready(Some(Ok(item))) =>
82-
try_ready!(self.as_mut().try_start_send(cx, item)),
82+
ready!(self.as_mut().try_start_send(cx, item))?,
8383
Poll::Ready(Some(Err(e))) => return Poll::Ready(Err(e)),
8484
Poll::Ready(None) => {
85-
try_ready!(self.as_mut().sink().as_pin_mut().expect(INVALID_POLL)
86-
.poll_close(cx));
85+
ready!(self.as_mut().sink().as_pin_mut().expect(INVALID_POLL).poll_close(cx))?;
8786
self.as_mut().sink().set(None);
8887
return Poll::Ready(Ok(()))
8988
}
9089
Poll::Pending => {
91-
try_ready!(self.as_mut().sink().as_pin_mut().expect(INVALID_POLL)
92-
.poll_flush(cx));
90+
ready!(self.as_mut().sink().as_pin_mut().expect(INVALID_POLL).poll_flush(cx))?;
9391
return Poll::Pending
9492
}
9593
}

0 commit comments

Comments
 (0)