tokio-rs / loom

Concurrency permutation testing tool for Rust.
MIT License
2.15k stars 112 forks source link

Detect simultaneous borrow and drop of UnsafeCell #351

Open e00E opened 6 months ago

e00E commented 6 months ago

Dropping an UnsafeCell or calling into_inner can be seen as mutable access, which is not allowed to happen while another borrow exists.

The downside of this change is the added Drop implementation of UnsafeCell. This restricts some uses of UnsafeCell that were previously allowed related to drop check.

I removed one of the tests because it stops working with this change due to double panic. Fixing it is awkward.

I went with an approach using unsafe. It is possible to implement this safely but it has too much overhead. We would have to wrap the data field with Option to allow safely taking. This is fine but we would also need to Box it because the type parameter T is ?Sized, which cannot be put into Option.

fixes #349