Pin-project and ?Sized

This struct compiles fine:

struct S<'a, T: ?Sized, U: ?Sized> {
	x: Pin<&'a mut T>,
	y: Pin<&'a mut U>,

However, the moment I add #[pin_project] in front of it, it fails, complaining that T needs to be Sized. I don’t understand why. S doesn’t have a T in it. None of the projections of S, as far as I can tell, should have Ts in them either (they should only have various kinds of pointers to Ts). Curiously, if T is Sized and U is ?Sized, pin-project is perfectly happy. Also, even if I change the order of the fields, pin-project still complains about T and not U!

What’s going on here?

pin-project is all about to allow obtaining Pin<&mut Field> or &mut Field from Pin<&mut Struct> where the Struct is !Unpin. Since all the fields of your struct is Unpin the S itself is Unpin, so you don't need pin_project attribute on it.

1 Like

Ah, the reason I was using pin-project is that I received a Pin<&mut S>, and I couldn’t seem to accomplish splitting borrows via the Pin<&mut S>. But I suppose if S is Unpin, should one instead just unwrap the Pin<&mut S> into an &mut S and do the splitting borrows from there?

Yeah, that's all.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.