Unique references to temporary empty arrays are not actually unique #74154
Labels
A-array
Area: [T; N]
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I expected this code to compile and exit without effect; instead, I get an assertion error. It seems that, when passing in unique references to temporary empty slices, the underlying pointers nonetheless alias.
I expected all such pointers to never alias; this even holds when replacing
[T]
above with the ZST[T; 0]
, which makes it significantly more worrying, since it does not hold for the same code using()
.I don't know if this behavior is actually specified, but I'd like an answer to whether this is a miscompilation or (un)documented implementation-defined behavior. At any rate, I wonder if it would be a good idea to make this behavior consistent for all ZST temporaries...
Also, I aught to mention that this is about ZSTs lying in distinct allocations. For a type such as
((), ())
, we expect the two unit values to have the same addresses. The closest mention of this I could find in the nomicon to this was the implementation ofVec<()>
, but that's still regarding same-allocation references, so that didn't give me a particularly satisfying answer.Meta
This issue is reproducible on latest beta and nightly.
I could not find an issue corresponding to this bug; feel free to close as duplicate.
The text was updated successfully, but these errors were encountered: