Description
Consider the following code:
#[test]
fn foo() {
loom::model(|| {
let a: loom::cell::UnsafeCell<()> = Default::default();
let first_ref = a.get();
let second_ref = a.get_mut();
});
}
The test fails because loom correctly detects that mutable access is not allowed while there is already immutable access.
Now change the last line of the code:
#[test]
fn foo() {
loom::model(|| {
let a: loom::cell::UnsafeCell<()> = Default::default();
let first_ref = a.get();
std::mem::drop(a);
});
}
Loom no longer detects an error.
This is surprising because dropping could be considered a write. For example, if instead of ()
I was using a type with a custom Drop implementation, then I would get a mutable reference to self
. This write doesn't go through UnsafeCell but it still leads to the reference guarantees being violated.
This behavior might be intentional because the documentation for ConstPtr says that Loom doesn't track liveness. I'm not sure. I did not find an existing issue about this topic so I created one. If the behavior is intentional, then this issue can be closed and can serve as documentation for the reason.