Skip to content

Regression: cannot return value referencing function parameter self #65

@taiki-e

Description

@taiki-e

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions