mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-11-24 12:16:25 +00:00
Merge pull request #532 from salsa-rs/fix-guard-assertion
Fix assertion for same DB in `DbGuard`
This commit is contained in:
commit
b0ee16211e
1 changed files with 9 additions and 5 deletions
|
@ -83,12 +83,16 @@ impl LocalState {
|
|||
impl<'s> DbGuard<'s> {
|
||||
fn new(state: &'s LocalState, db: &dyn Database) -> Self {
|
||||
if let Some(current_db) = state.database.get() {
|
||||
let new_db = NonNull::from(db);
|
||||
|
||||
// Already attached? Assert that the database has not changed.
|
||||
assert_eq!(
|
||||
current_db,
|
||||
NonNull::from(db),
|
||||
"cannot change database mid-query",
|
||||
);
|
||||
// NOTE: It's important to use `addr_eq` here because `NonNull::eq` not only compares the address but also the type's metadata.
|
||||
if !std::ptr::addr_eq(current_db.as_ptr(), new_db.as_ptr()) {
|
||||
panic!(
|
||||
"Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}",
|
||||
);
|
||||
}
|
||||
|
||||
Self { state: None }
|
||||
} else {
|
||||
// Otherwise, set the database.
|
||||
|
|
Loading…
Reference in a new issue