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

provide project method on &mut Pin<&mut Self> #345

Closed
ijackson opened this issue Jun 1, 2022 · 2 comments
Closed

provide project method on &mut Pin<&mut Self> #345

ijackson opened this issue Jun 1, 2022 · 2 comments
Labels
C-question Category: A question

Comments

@ijackson
Copy link

ijackson commented Jun 1, 2022

AFAICT it is not possible, given a function which takes Pin<&mut Sefl>, to make two function calls in turn which take Pin<&mut Self>. This is because the borrow checker's special logic for permitting this for &mut Self does not apply to Pin<&mut Self>.

I think it would be possible to solve this problem if pin_project provided something like this:

    fn project_mut(self: &mut Pin<&mut Self>) -> ....

It seems that this was previously done, but this was changed in #89. Obviously I'm not suggesting it ought to be changed back. But I don't see any reason why it wouldn't be sensible to provide both. I think this should be sound because the outer &mut guarantees unique ownership of the inner &mut.

Would you welcome a MR to provide this other method, perhaps optionally?

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a538875119bf28650f67540fe94a440f

@taiki-e
Copy link
Owner

taiki-e commented Jun 2, 2022

As discussed in #89, you can use .as_mut() to reborrow Pin<&mut Self>.

-      self.project().field; // ERROR *self` moved due to this method call
+      self.as_mut().project().field;
- pin_ref.takes_pin();
- pin_ref.takes_pin(); // ERROR value used here after move
+ pin_ref.as_mut().takes_pin();
+ pin_ref.takes_pin();

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=826520ca2b49581ce0a8d9a89a4c734e

@taiki-e taiki-e closed this as completed Jun 2, 2022
@taiki-e taiki-e added the C-question Category: A question label Jun 2, 2022
@ijackson
Copy link
Author

ijackson commented Jun 2, 2022

Oh. Thank you for educating me and sorry for wasting your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: A question
Projects
None yet
Development

No branches or pull requests

2 participants