Skip to content

Commit 9c83eb1

Browse files
committed
fix: remove unsafe Send and Sync implementations
1 parent c4e6664 commit 9c83eb1

3 files changed

Lines changed: 39 additions & 9 deletions

File tree

‎canyon_core/src/connection/db_connector.rs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ pub enum DatabaseConnector {
2525
MySQL(MySQLConnector),
2626
}
2727

28-
unsafe impl Send for DatabaseConnector {}
29-
unsafe impl Sync for DatabaseConnector {}
30-
3128
crate::impl_db_connection_for_db_connector!(DatabaseConnector);
3229
crate::impl_db_connection_for_db_connector!(&DatabaseConnector);
3330
crate::impl_db_connection_for_db_connector!(&mut DatabaseConnector);
@@ -62,3 +59,15 @@ impl DatabaseConnector {
6259
}
6360
}
6461
}
62+
63+
#[cfg(test)]
64+
mod tests {
65+
use super::DatabaseConnector;
66+
67+
fn assert_send_sync<T: Send + Sync>() {}
68+
69+
#[test]
70+
fn database_connector_is_send_and_sync_without_manual_unsafe_impls() {
71+
assert_send_sync::<DatabaseConnector>();
72+
}
73+
}

‎canyon_core/src/query/query.rs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ impl AsRef<str> for Query<'_> {
2222
}
2323
}
2424

25-
unsafe impl Send for Query<'_> {}
26-
unsafe impl Sync for Query<'_> {}
27-
2825
impl<'a> Query<'a> {
2926
/// Constructs a new [`Self`] but receiving the number of expected query parameters, allowing
3027
/// to pre-allocate the underlying linear collection that holds the arguments to the exact capacity,
@@ -81,3 +78,15 @@ impl<'a> Query<'a> {
8178
}
8279

8380
impl<'a> Transaction for Query<'a> {}
81+
82+
#[cfg(test)]
83+
mod tests {
84+
use super::Query;
85+
86+
fn assert_send_sync<T: Send + Sync>() {}
87+
88+
#[test]
89+
fn query_is_send_and_sync_without_manual_unsafe_impls() {
90+
assert_send_sync::<Query<'static>>();
91+
}
92+
}

‎canyon_core/src/query/querybuilder/types/mod.rs‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pub struct QueryBuilder<'a, P: BackendEmittable<'a> + 'a> {
2929
pub(crate) params: Vec<&'a dyn QueryParameter>,
3030
}
3131

32-
unsafe impl<'a, P: BackendEmittable<'a>> Send for QueryBuilder<'a, P> {}
33-
unsafe impl<'a, P: BackendEmittable<'a>> Sync for QueryBuilder<'a, P> {}
34-
3532
impl<'a, P: BackendEmittable<'a> + 'a> QueryBuilder<'a, P> {
3633
pub fn new(
3734
table_metadata: impl Into<TableMetadata<'a>>,
@@ -139,6 +136,21 @@ impl<'a, P: BackendEmittable<'a> + 'a> QueryBuilder<'a, P> {
139136
}
140137
}
141138

139+
#[cfg(test)]
140+
mod thread_safety_tests {
141+
use super::{DeleteQueryBuilder, InsertQueryBuilder, SelectQueryBuilder, UpdateQueryBuilder};
142+
143+
fn assert_send_sync<T: Send + Sync>() {}
144+
145+
#[test]
146+
fn built_in_query_builders_are_send_and_sync_without_manual_unsafe_impls() {
147+
assert_send_sync::<DeleteQueryBuilder<'static>>();
148+
assert_send_sync::<InsertQueryBuilder<'static>>();
149+
assert_send_sync::<SelectQueryBuilder<'static>>();
150+
assert_send_sync::<UpdateQueryBuilder<'static>>();
151+
}
152+
}
153+
142154
mod __impl {
143155
use crate::query::bounds::FieldIdentifier;
144156
use crate::query::operators::Operator;

0 commit comments

Comments
 (0)