Holding an impl AsMut<[u8]> and multiple &mut [u8] into it at the same time

Without having read all the context here -- it is indeed the case that just because two pointers compare equal, does not mean they are interchangable. When a new allocation is made in the same place as an old one, you must use new pointers and must not use old pointers that have been created before the new allocation. This is a light form of the "pointer zapping" rule in C/C++ which says that pointers to deallocated memory have indeterminate value; in Rust their value is determined (so comparison is still permitted) but the pointers are permanently undereferencable.

For this to actually be an error you need addresses to be reuse, which Miri currently doesn't do -- and even if it did, it would be hard to trigger this problem because it only happens when the exact two allocations involved in the comparison reuse addresses.


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.