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

Regression: cannot return value referencing function parameter self #65

Closed
taiki-e opened this issue Sep 3, 2019 · 3 comments · Fixed by #69
Closed

Regression: cannot return value referencing function parameter self #65

taiki-e opened this issue Sep 3, 2019 · 3 comments · Fixed by #69
Assignees
Labels
A-pin-projection Area: #[pin_project] C-bug Category: related to a bug. regression-from-0.3-to-0.4 Regression from 0.3 to 0.4
Milestone

Comments

@taiki-e
Copy link
Owner

taiki-e commented Sep 3, 2019

Caused by #47.

Such code is used a lot in futures etc., so I would like to support it...
However, I'm not sure if this can be fixed by ways other than changing self argument to self: Pin<&mut Self>.

Code:

use std::pin::Pin;

#[pin_project::pin_project]
struct Struct<T, U> {
    #[pin]
    pinned: T,
    unpinned: U,
}

impl<T, U> Struct<T, U> {
    fn get_pin_mut<'a>(mut self: Pin<&'a mut Self>) -> Pin<&'a mut T> {
        self.project().pinned
    }
}

Error:

error[E0515]: cannot return value referencing function parameter `self`
  --> src/lib.rs:33:9
   |
33 |         self.project().pinned
   |         ----^^^^^^^^^^^^^^^^^
   |         |
   |         returns a value referencing data owned by the current function
   |         `self` is borrowed here

playground (current)

playground (previous)

Related: rust-lang/rust#54934

@taiki-e taiki-e added this to the v0.4 milestone Sep 3, 2019
@taiki-e
Copy link
Owner Author

taiki-e commented Sep 3, 2019

cc @Aaron1011

@taiki-e
Copy link
Owner Author

taiki-e commented Sep 3, 2019

@Aaron1011
Copy link
Collaborator

I've found a solution - I'll be opening a PR soon.

@taiki-e taiki-e assigned Aaron1011 and taiki-e and unassigned taiki-e Sep 4, 2019
bors bot added a commit that referenced this issue Sep 4, 2019
69: Add 'project_into' method to #[pin_project] types r=taiki-e a=Aaron1011

This method consumes takes a 'Pin<&mut Self>' by value, instead
of by mutable reference. This allows us to give the projection
struct/enum a longer lifetime, which is required when returning it
from a function

Fixes #65

Co-authored-by: Aaron Hill <[email protected]>
Co-authored-by: Taiki Endo <[email protected]>
@bors bors bot closed this as completed in 426683b Sep 4, 2019
@taiki-e taiki-e added C-bug Category: related to a bug. regression-from-0.3-to-0.4 Regression from 0.3 to 0.4 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. regression-from-0.3-to-0.4 Regression from 0.3 to 0.4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants