diff --git a/futures-test/src/assert_unmoved.rs b/futures-test/src/assert_unmoved.rs index 112c690f87..ec81b662a5 100644 --- a/futures-test/src/assert_unmoved.rs +++ b/futures-test/src/assert_unmoved.rs @@ -40,7 +40,7 @@ impl AssertUnmoved { } } - fn poll_with(mut self: Pin<&mut Self>, f: impl FnOnce(Pin<&mut T>) -> U) -> U { + fn poll_with<'a, U>(mut self: Pin<&'a mut Self>, f: impl FnOnce(Pin<&'a mut T>) -> U) -> U { let cur_this = &*self as *const Self; if self.this_ptr.is_null() { // First time being polled @@ -158,19 +158,8 @@ impl AsyncSeek for AssertUnmoved { } impl AsyncBufRead for AssertUnmoved { - fn poll_fill_buf(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - // FIXME: We cannot use `poll_with` here because it causes a lifetime error. - let cur_this = &*self as *const Self; - if self.this_ptr.is_null() { - // First time being polled - *self.as_mut().project().this_ptr = cur_this; - } else { - assert_eq!( - self.this_ptr, cur_this, - "AssertUnmoved moved between poll calls" - ); - } - self.project().inner.poll_fill_buf(cx) + fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.poll_with(|r| r.poll_fill_buf(cx)) } fn consume(self: Pin<&mut Self>, amt: usize) { diff --git a/futures-test/src/interleave_pending.rs b/futures-test/src/interleave_pending.rs index b065116f42..7bc8706388 100644 --- a/futures-test/src/interleave_pending.rs +++ b/futures-test/src/interleave_pending.rs @@ -57,10 +57,10 @@ impl InterleavePending { self.inner } - fn poll_with( - self: Pin<&mut Self>, + fn poll_with<'a, U>( + self: Pin<&'a mut Self>, cx: &mut Context<'_>, - f: impl FnOnce(Pin<&mut T>, &mut Context<'_>) -> Poll, + f: impl FnOnce(Pin<&'a mut T>, &mut Context<'_>) -> Poll, ) -> Poll { let this = self.project(); if *this.pended { @@ -185,19 +185,7 @@ impl AsyncSeek for InterleavePending { impl AsyncBufRead for InterleavePending { fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - // FIXME: We cannot use `poll_with` here because it causes a lifetime error. - let this = self.project(); - if *this.pended { - let next = this.inner.poll_fill_buf(cx); - if next.is_ready() { - *this.pended = false; - } - next - } else { - cx.waker().wake_by_ref(); - *this.pended = true; - Poll::Pending - } + self.poll_with(cx, R::poll_fill_buf) } fn consume(self: Pin<&mut Self>, amount: usize) {