We have seen a few cases in libstd where the rule that just creating a mutable reference already asserts uniqueness is a problem:
In some cases, even just creating a shared ref is an issue, as it conflicts with a recently created mutable ref:
So maybe we assert uniqueness to aggressively here? Maybe mutable references should only become unique on first write, or so? I am not sure what that would look like though. (In principle this could also happen with shared references but I have not seen that.)
I'll use this issue to collect such cases.
However, there are also cases where people want the extra UB to get more optimizations:
We have seen a few cases in libstd where the rule that just creating a mutable reference already asserts uniqueness is a problem:
VecDequecreating overlapping mutable references.BTreeMapcreating mutable references that overlap with shared references.LinkedListcreating overlapping mutable references.Vec::pushinvalidating existing references into the vector. The typed-arena crate ran into the same problem.ptr::replaceare forbidden even though they should probably be allowed.In some cases, even just creating a shared ref is an issue, as it conflicts with a recently created mutable ref:
So maybe we assert uniqueness to aggressively here? Maybe mutable references should only become unique on first write, or so? I am not sure what that would look like though. (In principle this could also happen with shared references but I have not seen that.)
I'll use this issue to collect such cases.
However, there are also cases where people want the extra UB to get more optimizations: