stable_deref_trait
stable_deref_trait copied to clipboard
Document how Pin != StableDeref
TL;DR: Pin<P>
fails two guarantees of StableDeref
, even when Target: !Unpin
: it does not guarantee that <P as Deref>::deref
and <P as DerefMut>::deref_mut
go to the same place, and it does not even guarantee that two invocations of <P as Deref>::deref
go to the same place.
Could we just impl StableDeref
for Pin<P>
where P: StableDeref
?
cc @Storyyeller
I'm not sure how failing to satisfy these would break safety in crates like rental or owning_ref though. Any clue?
EDIT: Oh nevermind I found: if Deref
points to somewhere that moves when the struct moves (e.g. &self.some_field
), it breaks. Pin seems to not guarantee that is not the case.