Skip to content
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

Odd unused warning on non pinned item #59

Closed
LucioFranco opened this issue Sep 2, 2019 · 5 comments
Closed

Odd unused warning on non pinned item #59

LucioFranco opened this issue Sep 2, 2019 · 5 comments
Labels
A-pin-projection Area: #[pin_project] C-bug Category: related to a bug.

Comments

@LucioFranco
Copy link
Sponsor

I'm getting an odd dead_code warning when im obviously using key in the Ready(Ok(svc)) branch. I think this has to do with the pin-project macro.

#[pin_project]
#[derive(Debug)]
struct UnreadyService<K, S, Req> {
    // This is a false positive
	// this is warning that it is unused
    key: Option<K>,
    #[pin]
    cancel: oneshot::Receiver<()>,
    #[pin]
    ready: Ready<S, Req>,
}

impl<K, S: Service<Req>, Req> Future for UnreadyService<K, S, Req> {
    type Output = Result<(K, S), (K, Error<S::Error>)>;

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        let me = self.project();

        if let Poll::Ready(Ok(())) = me.cancel.poll(cx) {
            let key = self.key.take().expect("polled after ready");
            return Poll::Ready(Err((key, Error::Canceled)));
        }

        match me.ready.poll(cx) {
            Poll::Pending => Poll::Pending,
            Poll::Ready(Ok(svc)) => {
				// but it is used here
                let key = self.key.take().expect("polled after ready");
                Ok((key, svc)).into()
            }
            Poll::Ready(Err(e)) => {
                let key = self.key.take().expect("polled after ready");
                Err((key, Error::Inner(e))).into()
            }
        }
    }
}
@LucioFranco
Copy link
Sponsor Author

cc @taiki-e

@taiki-e
Copy link
Owner

taiki-e commented Sep 2, 2019

@LucioFranco Thanks for the reporting! I think it was probably fixed in #57. I will release the next version soon.

@LucioFranco
Copy link
Sponsor Author

ahhh awesome I should have looked deeper, have to say loving this lib!!!

@taiki-e
Copy link
Owner

taiki-e commented Sep 2, 2019

Published 0.4.0-alpha.7. Could you check if the problem has been fixed?

@LucioFranco
Copy link
Sponsor Author

It has, thanks <3

@taiki-e taiki-e added C-bug Category: related to a bug. A-pin-projection Area: #[pin_project] labels Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pin-projection Area: #[pin_project] C-bug Category: related to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants