If we add a Cell<*mut Self> member to Heap<T> that is conditionally compiled, initialize it to null, and set it to self as *const Self whenever Heap::set is invoked, we can assert that the cell value is either null or equal to self as *const Self. This will automatically assert any time that a Heap value is set to a non-default value, moved (thus invalidating the pointer stored by SM), and set once more. This can't flag any moves that occur when no mutation follows, but it's better than nothing.
If we add a
Cell<*mut Self>
member toHeap<T>
that is conditionally compiled, initialize it to null, and set it toself as *const Self
wheneverHeap::set
is invoked, we can assert that the cell value is either null or equal toself as *const Self
. This will automatically assert any time that a Heap value is set to a non-default value, moved (thus invalidating the pointer stored by SM), and set once more. This can't flag any moves that occur when no mutation follows, but it's better than nothing.