Stream: t-lang/wg-unsafe-code-guidelines

Topic: linked-list traversal


Jake Goulding (Nov 14 2018 at 01:52, on Zulip):

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 [A, C], then increment to have [A, D] then [B, D]?

Jake Goulding (Nov 14 2018 at 01:54, on Zulip):

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?

Gankro (Nov 14 2018 at 02:01, on Zulip):

the current guidelines are that reachability isn’t transitive through references, but also your links are raw pointers so it’s super fine

Jake Goulding (Nov 14 2018 at 02:23, on Zulip):

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?

RalfJ (Nov 14 2018 at 09:04, on Zulip):

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.)

RalfJ (Nov 14 2018 at 09:06, on Zulip):

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.

Jake Goulding (Nov 14 2018 at 15:18, on Zulip):

I'd be happy to write a testcase, as soon as I wrangle NLL into submission...

Last update: Nov 19 2019 at 17:50UTC