This is great! Props to @cramertj for having the presence of mind to think of this, and to @RalfJung for carrying through the investigation. 
I only have three random thoughts.
-
It’s vaguely bothered me for a while that Rust doesn’t have a clear answer for how to safely implement things like Qt’s
QObjecthierarchies, which have both parent-child and child-parent pointers, without resorting toRcandWeakpointers (which C++ doesn’t need to). This seems to be exactly what is needed. I don’t know if one would typically want to do such a thing, but it’s good to know how it’d now (hopefully, presumably) be possible! -
Could
RefCelladd a bit to its borrow flags to keep track of whether its contents are pinned, slash would doing this make sense? A bit that once set, stays set, and if it is set, you can getPins out of theRefCellbut not&muts. (It seems we have wisely refrained from exposing aBorrowStateenumerating all of the possible states aRefCellcan be in.) -
Could you use this to implement a doubly-linked list in safe code? Or at least, less-
unsafecode? Not as a (publicly) intrusive collection, but something like theLinkedListAPI instd.