We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 8788180 + 354dc0e commit b0ee162Copy full SHA for b0ee162
src/local_state.rs
@@ -83,12 +83,16 @@ impl LocalState {
83
impl<'s> DbGuard<'s> {
84
fn new(state: &'s LocalState, db: &dyn Database) -> Self {
85
if let Some(current_db) = state.database.get() {
86
+ let new_db = NonNull::from(db);
87
+
88
// Already attached? Assert that the database has not changed.
- assert_eq!(
- current_db,
89
- NonNull::from(db),
90
- "cannot change database mid-query",
91
- );
+ // 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!(
92
+ "Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}",
93
+ );
94
+ }
95
96
Self { state: None }
97
} else {
98
// Otherwise, set the database.
0 commit comments