Skip to content

Commit b0ee162

Browse files
authored
Merge pull request #532 from salsa-rs/fix-guard-assertion
Fix assertion for same DB in `DbGuard`
2 parents 8788180 + 354dc0e commit b0ee162

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/local_state.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,16 @@ impl LocalState {
8383
impl<'s> DbGuard<'s> {
8484
fn new(state: &'s LocalState, db: &dyn Database) -> Self {
8585
if let Some(current_db) = state.database.get() {
86+
let new_db = NonNull::from(db);
87+
8688
// Already attached? Assert that the database has not changed.
87-
assert_eq!(
88-
current_db,
89-
NonNull::from(db),
90-
"cannot change database mid-query",
91-
);
89+
// NOTE: It's important to use `addr_eq` here because `NonNull::eq` not only compares the address but also the type's metadata.
90+
if !std::ptr::addr_eq(current_db.as_ptr(), new_db.as_ptr()) {
91+
panic!(
92+
"Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}",
93+
);
94+
}
95+
9296
Self { state: None }
9397
} else {
9498
// Otherwise, set the database.

0 commit comments

Comments
 (0)