uazu / qcell

Statically-checked alternatives to RefCell and RwLock
Apache License 2.0
356 stars 22 forks source link

Check whether rw2/rw3 are sound #7

Closed uazu closed 4 years ago

uazu commented 4 years ago

It was pointed out that maybe it's possible to get access to both a structure and a member of that structure at the same time using rw2, which would mean two &mut to the same memory region. Try to create an example which reproduces this, then see if there's any way to save the functionality.

uazu commented 4 years ago

After working through this, I believe there is no risk of unsoundness here. Since the rw2 and rw3 functions accept a reference to a QCell type (for example), for there to be a reference inside the same area of memory, we'd need a QCell within a QCell with the same owner. You'd already need a borrow on the outer cell to get access to the inner cell, so either we can get no further mut borrow because it's already a mut borrow, or it will be an immutable borrow (which means no issue). So I'll close this until someone can demonstrate a real problem here.