Description
Box
and Vec
have internally used the Unique
pointer type since Forever (TM). The intention was that that gives some some special aliasing rules. Box
is even emitting noalias
to LLVM, so we might have optimizations already exploit those aliasing rules.
However, it looks like none of this is actually surfaced in the documentation (Cc @saethlin), leading to a significant risk that code out there might violate whatever the aliasing rules end up being.
For whatever it's worth, Miri with Stacked Borrows does treat Box
rather similar to &mut
, but does not do anything special with Vec
. I have ideas for how the Next Aliasing Model can treat Unique
special (so Box
itself no longer needs to be special, at least if we decide to "look into" private fields when applying aliasing rules which is its own whole separate discussion), bot nothing concrete yet.
For each of these types we basically have two options:
- Keep going with the intention of making them have aliasing guarantees. Then we should probably put something into the docs. This might be considered a breaking change by some.
- Give up on this plan (and, in the case of
Box
, remove thenoalias
and the special treatment in Miri). This will make some people very sad. Cc @Gankra @nikomatsakis