-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
pin_project cannot be used with structs that hold mutable references #226
Comments
Hmm... I could reproduce this without pin-project (playground): pub struct Foo<'a> {
buf: &'a mut [u8],
}
impl<'a> Foo<'a> {
fn foo(self: std::pin::Pin<&mut Self>) {
self.buf = &mut self.buf[1..];
}
} I guess this related to rust-lang/rust#54934, but I'll look into this more. |
Ok, this looks like rust-lang/rust#72337 and can be fixed by adding lifetime impl<'a, R> Foo<'a, R> {
- fn foo(self: std::pin::Pin<&mut Self>) {
+ fn foo(self: std::pin::Pin<&'a mut Self>) {
let this = self.project();
*this.buf = &mut this.buf[1..];
}
} |
Oh. You're right, this isn't related to pin-project at all, sorry for having bothered you with it! This being said, your solution unfortunately requires the Thank you! :D |
I also commented on rust-lang/rust#72477, but this way should fix it completely: #[pin_project::pin_project]
pub struct A<'a, R> {
buf: &'a mut [u8],
#[pin]
stuff: R,
}
impl<'a> Foo<'a> {
fn foo(mut self: std::pin::Pin<&mut Self>) {
let this = self.project();
let (_, rest) = std::mem::replace(&mut *this.buf, &mut []).split_at_mut(1);
*this.buf = rest;
}
} |
Hello,
I just tried using
pin-project
, as it looks like a really nice helper!However, while doing so, I hit a wall: with
pin-project = "0.4.17"
,fails to compile with this error message:
Weirdly enough, replacing
&'a mut
by&'a
works, so I'd guess something has been implemented specifically for&'a
but hasn't been implemented for&'a mut
?Do you think it'd be possible to handle this in
pin-project
, or is it something that can't be fixed and I should just not use it? :)The text was updated successfully, but these errors were encountered: