Uhhhhh, guys?
You don't need an UnsafeCell if you have a *const T
or *mut T
.
- If you did, then it would be difficult to use
UnsafeCell::get
safely, as you would have to be paranoid about the possible accidental construction of a&*mut T
(e.g. when you Clone a pointer). If you're still not convinced, here's proof that they disable all of the same optimizations.
Wait a second, I misread the code I linked. What the heck!?!?!
unsafe impl<T: ?Sized> Freeze for *const T {}
unsafe impl<T: ?Sized> Freeze for *mut T {}
That... that can't be right!
@cuviper how did you construct those playground tests before? I'm having a difficult time getting the functions to not be eliminated as dead code. (I wish the playground had a --lib
mode...).
(edit: never mind, I finally spotted the playground link in your post)
I may need to read up on LLVM's noalias. Perhaps it only extends to data accessed through an offset of the pointer itself, and not to data accessed through another layer of indirection.