If I have a linked list, is it safe to have mutable references to two distinct nodes at the same time? That is, could I have
A -> B -> C -> D
Keeping mutable references to [
C], then increment to have [
D] then [
Or is the fact that
C is reachable from
A enough to declare this UB? If that's the case, do I just need to to keep both as raw pointers and only dereference for exceedingly short spans of time?
the current guidelines are that reachability isn’t transitive through references, but also your links are raw pointers so it’s super fine
but also your links are raw pointers
Why do you say that? Assuming it's some form of
Box which thus has a raw pointer somewhere in it?
The current guidelines don't say much.^^ But, @Jake Goulding could you just write some little testcase doing it and send me the code? (The miri on playground unfortunately doesn't implement the latest version of Stacked Borrows, still waiting for a rustc PR to land.)
Stacked Borrows says: The important part is that
&mut is unique, i.e. between two uses (where use is defined very liberally, and includes assignment -- i.e. , in
let x = y,
y gets "used"), there must not have been any access to the memory this reference points to, except through "derived" references -- i.e., references created from the reference in question with reborrowing.
I'd be happy to write a testcase, as soon as I wrangle NLL into submission...