Skip to content

Commit

Permalink
Merge pull request #532 from salsa-rs/fix-guard-assertion
Browse files Browse the repository at this point in the history
Fix assertion for same DB in `DbGuard`
  • Loading branch information
nikomatsakis authored Jul 28, 2024
2 parents 8788180 + 354dc0e commit b0ee162
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/local_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b0ee162

Please sign in to comment.