stable_deref_trait icon indicating copy to clipboard operation
stable_deref_trait copied to clipboard

Document how Pin != StableDeref

Open CAD97 opened this issue 4 years ago • 3 comments

Discussion on urlo.

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.

CAD97 avatar Aug 13 '19 21:08 CAD97

Could we just impl StableDeref for Pin<P> where P: StableDeref?

Manishearth avatar Mar 13 '20 06:03 Manishearth

cc @Storyyeller

Manishearth avatar Mar 13 '20 06:03 Manishearth

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.

Ten0 avatar Aug 04 '20 00:08 Ten0