Can either of these be optimized to just return false? For the first function, we can construct a zero-length slice from NonNull::dangling, and we can produce two slices that have the same pointer. But can rustc ignore that fact?
Is NonNull::<T>::dangling guaranteed to always return a pointer whose numeric value is the alignment of T?
You are probably confusing "overlap" with "same address". In Rust, two regions overlap if and only if they have a (non-empty) memory region that is part of both allocations.
Mutable references aren't allowed to overlap, but they can have the same address if at least one of them is zero-sized, because a zero-sized value never overlaps with anything (since the length of a potential overlap would always be zero).
This indicates that memory locations accessed via pointer values based on the argument or return value are not also accessed, during the execution of the function, via pointer values not based on the argument or return value.
Since that's about accessed, it doesn't mean that the pointers aren't the same, because if it's not accessed at all, then it would meet the requirements for what LLVM knows about it. (As I understand it, at least.)
I don't understand the question. The addresses of two zero-sized objects may be the same or different. Thus the compiler can't say with certainty that they will or will not be equal. They may or may not be equal.
That's interesting. Does that guarantee facilitate something? (I.e., is there something, in, say, tokio, that requires references to ZSTs to have stable addresses?) Does allocating a ZST give you a "new" address?