4 ms·
For the record, Rust does have a "not noalias" builtin magic type in the standard library: UnsafeCell. https://doc.rust-lang.org/stable/std/cell/struct.UnsafeC
by simonask 2y ago
For the record, Rust does have a "not noalias" builtin magic type in the standard library: UnsafeCell.
https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell.html https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell....
- LegionMammal978 2y agoNo, UnsafeCell doesn't change any rules around non-aliasing for &mut/Box. (E.g., if you move a Box<UnsafeCell<T>>, it will still invalidate any pointers to the data.) All it does is change the rules around immutability for & references. &T is "not noalias" regardless of UnsafeCell, but it's immutable in its absence. Meanwhile, there is a magic "not noalias" mechanism currently recognized by Miri, in the form of !Unpin types. But this is considered a temporary hack to keep it from complaining about pinned futures that reference their own fields, in the absence of an actual language feature. Also, it only applies to accessing values through unique references, not to moving or writing to them by their binding.
- Rusky 2y ago&T is noalias - while there may be aliases none can write, which is the important thing - without UnsafeCell, and &UnsafeCell<T> loses noalias for that reason.