Skip to content

FnMut inside Pin complains about DerefMut not implemented #65489

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

Closed
roblabla opened this issue Oct 17, 2019 · 4 comments
Closed

FnMut inside Pin complains about DerefMut not implemented #65489

roblabla opened this issue Oct 17, 2019 · 4 comments
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@roblabla
Copy link
Contributor

When calling an FnMut() from inside a Pin, Rust complains that DerefMut is not implemented:

struct MyFuture<F> {
    f: F,
}

impl<F, T> core::future::Future for MyFuture<F>
where
    F: FnMut() -> Option<T> + Unpin,
{
    type Output = T;
    fn poll(mut self: core::pin::Pin<&mut Self>, cx: &mut core::task::Context) -> core::task::Poll<T> {
        (self.f)();
        core::task::Poll::Pending
    }
}

This seemingly equivalent piece of code works properly with no errors:

struct MyFuture<F> {
    f: F,
}

impl<F, T> core::future::Future for MyFuture<F>
where
    F: FnMut() -> Option<T> + Unpin,
{
    type Output = T;
    fn poll(mut self: core::pin::Pin<&mut Self>, cx: &mut core::task::Context) -> core::task::Poll<T> {
        let x = &mut *self; // Work around weird bug.
        (x.f)();
        core::task::Poll::Pending
    }
}
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 18, 2019
@Mark-Simulacrum
Copy link
Member

(&mut self.f)(); works too. Seems like probably we're not looking at DerefMut sufficiently or with the wrong ParamEnv perhaps?

@roblabla
Copy link
Contributor Author

roblabla commented Oct 21, 2019

Spent a couple minutes writing a more self-contained reproducer: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=70745ec56da08ff7a8aeee8fbead6488

Testing it in godbolt reveals that even Rust 1.0.0 didn't like it

@paulkernfeld
Copy link

I just pasted the first snippet into the Rust Playground with Rust 1.46 and it compiles, so maybe this issue is now fixed?

@roblabla
Copy link
Contributor Author

Indeed, this seems to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants