Checks required:
- P2 cannot be changed when P1 is not None. (Run-time check; the compiler has to recognize when it is necessary.)
- P1 can only be set to None or B. (Compile-time check)
- P1 must be set to None before B is destroyed. This avoids a dangling pointer. (Compile-time check when possible, otherwise run-time check.)
- Borrow checking must treat a borrow using P1 as a borrow of B.
These simple rules would maintain the invariant for the backpointer. This allows doubly-linked lists without unsafe code. The backpointer is "weak" and doesn't count as ownership. It's basically weak pointers with a count of either 0 or 1.