mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-10-23 12:49:57 +00:00
Panic in PanicGuard if it's not explicitly forgotten
This commit is contained in:
parent
c018196ffb
commit
0f4d1e8320
1 changed files with 11 additions and 3 deletions
|
@ -527,7 +527,7 @@ where
|
|||
panic_guard: PanicGuard<'_, DB, Q>,
|
||||
) {
|
||||
// No panic occurred, do not run the panic-guard destructor:
|
||||
std::mem::forget(panic_guard);
|
||||
panic_guard.forget();
|
||||
|
||||
// Overwrite the value, releasing the lock afterwards:
|
||||
let waiting = {
|
||||
|
@ -583,6 +583,10 @@ where
|
|||
fn new(map: &'db RwLock<FxHashMap<Q::Key, QueryState<DB, Q>>>, key: &'db Q::Key) -> Self {
|
||||
Self { map, key }
|
||||
}
|
||||
|
||||
fn forget(self) {
|
||||
std::mem::forget(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'db, DB, Q> Drop for PanicGuard<'db, DB, Q>
|
||||
|
@ -592,8 +596,12 @@ where
|
|||
{
|
||||
// FIXME(#24) -- handle parallel case
|
||||
fn drop(&mut self) {
|
||||
let mut map = self.map.write();
|
||||
let _ = map.remove(self.key);
|
||||
if std::thread::panicking() {
|
||||
let mut map = self.map.write();
|
||||
let _ = map.remove(self.key);
|
||||
} else {
|
||||
panic!(".forget() was not called")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue