Skip to content

Remove useless uses of Pin #2405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,22 @@ impl<T, U> Clone for UnboundedSender<T, U> {
}
}

#[pin_project::pin_project(PinnedDrop)]
pub(crate) struct Receiver<T, U> {
#[pin]
inner: mpsc::UnboundedReceiver<Envelope<T, U>>,
taker: want::Taker,
}

impl<T, U> Receiver<T, U> {
pub(crate) fn poll_next(
self: Pin<&mut Self>,
pub(crate) fn poll_recv(
&mut self,
cx: &mut task::Context<'_>,
) -> Poll<Option<(T, Callback<T, U>)>> {
let mut this = self.project();
match this.inner.poll_recv(cx) {
match self.inner.poll_recv(cx) {
Poll::Ready(item) => {
Poll::Ready(item.map(|mut env| env.0.take().expect("envelope not dropped")))
}
Poll::Pending => {
this.taker.want();
self.taker.want();
Poll::Pending
}
}
Expand All @@ -177,12 +174,11 @@ impl<T, U> Receiver<T, U> {
}
}

#[pin_project::pinned_drop]
impl<T, U> PinnedDrop for Receiver<T, U> {
fn drop(mut self: Pin<&mut Self>) {
impl<T, U> Drop for Receiver<T, U> {
fn drop(&mut self) {
// Notify the giver about the closure first, before dropping
// the mpsc::Receiver.
self.as_mut().taker.cancel();
self.taker.cancel();
}
}

Expand Down Expand Up @@ -279,8 +275,8 @@ mod tests {
impl<T, U> Future for Receiver<T, U> {
type Output = Option<(T, Callback<T, U>)>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.poll_next(cx)
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.poll_recv(cx)
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ cfg_server! {
}

cfg_client! {
#[pin_project::pin_project]
pub(crate) struct Client<B> {
callback: Option<crate::client::dispatch::Callback<Request<B>, http::Response<Body>>>,
#[pin]
rx: ClientRx<B>,
rx_closed: bool,
}
Expand Down Expand Up @@ -557,12 +555,12 @@ cfg_client! {
type RecvItem = crate::proto::ResponseHead;

fn poll_msg(
self: Pin<&mut Self>,
mut self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), crate::common::Never>>> {
let this = self.project();
debug_assert!(!*this.rx_closed);
match this.rx.poll_next(cx) {
let mut this = self.as_mut();
debug_assert!(!this.rx_closed);
match this.rx.poll_recv(cx) {
Poll::Ready(Some((req, mut cb))) => {
// check that future hasn't been canceled already
match cb.poll_canceled(cx) {
Expand All @@ -578,15 +576,15 @@ cfg_client! {
headers: parts.headers,
extensions: parts.extensions,
};
*this.callback = Some(cb);
this.callback = Some(cb);
Poll::Ready(Some(Ok((head, body))))
}
}
}
Poll::Ready(None) => {
// user has dropped sender handle
trace!("client tx closed");
*this.rx_closed = true;
this.rx_closed = true;
Poll::Ready(None)
}
Poll::Pending => Poll::Pending,
Expand Down
2 changes: 1 addition & 1 deletion src/proto/h2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ where
}
};

match Pin::new(&mut self.req_rx).poll_next(cx) {
match self.req_rx.poll_recv(cx) {
Poll::Ready(Some((req, cb))) => {
// check that future hasn't been canceled already
if cb.is_canceled() {
Expand Down