diff --git a/sqlx-core/src/sqlite/arguments.rs b/sqlx-core/src/sqlite/arguments.rs index 8d4c6618..e7c8ce6c 100644 --- a/sqlx-core/src/sqlite/arguments.rs +++ b/sqlx-core/src/sqlite/arguments.rs @@ -75,7 +75,6 @@ impl SqliteArgumentValue { let index = index as c_int; // https://sqlite.org/c3ref/bind_blob.html - #[allow(unsafe_code)] let status: c_int = match self { SqliteArgumentValue::Blob(value) => { // TODO: Handle bytes that are too large diff --git a/sqlx-core/src/sqlite/connection.rs b/sqlx-core/src/sqlite/connection.rs index 3fa1f90f..9c502cf0 100644 --- a/sqlx-core/src/sqlite/connection.rs +++ b/sqlx-core/src/sqlite/connection.rs @@ -43,7 +43,6 @@ pub struct SqliteConnection { // -#[allow(unsafe_code)] unsafe impl Send for SqliteConnectionHandle {} async fn establish(url: Result) -> crate::Result { @@ -71,7 +70,6 @@ async fn establish(url: Result) -> crate::Result - #[allow(unsafe_code)] let status = unsafe { sqlite3_open_v2(filename.as_ptr(), &mut handle, flags, null()) }; if handle.is_null() { @@ -82,7 +80,6 @@ async fn establish(url: Result) -> crate::Result) -> crate::Result Self { - #[allow(unsafe_code)] let code: c_int = unsafe { sqlite3_extended_errcode(conn) }; - #[allow(unsafe_code)] let message = unsafe { let err = sqlite3_errmsg(conn); debug_assert!(!err.is_null()); diff --git a/sqlx-core/src/sqlite/executor.rs b/sqlx-core/src/sqlite/executor.rs index 83ce05c8..3a9bbf43 100644 --- a/sqlx-core/src/sqlite/executor.rs +++ b/sqlx-core/src/sqlite/executor.rs @@ -60,7 +60,6 @@ impl SqliteConnection { // completed INSERT, UPDATE or DELETE statement. // https://www.sqlite.org/c3ref/changes.html - #[allow(unsafe_code)] let changes = unsafe { sqlite3_changes(self.handle()) }; changes as u64 } diff --git a/sqlx-core/src/sqlite/mod.rs b/sqlx-core/src/sqlite/mod.rs index 06d30eca..5d59db47 100644 --- a/sqlx-core/src/sqlite/mod.rs +++ b/sqlx-core/src/sqlite/mod.rs @@ -1,5 +1,10 @@ //! **SQLite** database and connection types. +// SQLite is a C library. All interactions require FFI which is unsafe. +// All unsafe blocks should have comments pointing to SQLite docs and ensuring that we maintain +// invariants. +#![allow(unsafe_code)] + mod arguments; mod connection; mod cursor; diff --git a/sqlx-core/src/sqlite/row.rs b/sqlx-core/src/sqlite/row.rs index 5a7226d4..a761dcf6 100644 --- a/sqlx-core/src/sqlite/row.rs +++ b/sqlx-core/src/sqlite/row.rs @@ -15,10 +15,7 @@ impl crate::row::private_row::Sealed for SqliteRow<'_> {} // safe across threads as long as we don't call [sqlite3_step] // That should not be possible as long as an immutable borrow is held on the connection -#[allow(unsafe_code)] unsafe impl Send for SqliteRow<'_> {} - -#[allow(unsafe_code)] unsafe impl Sync for SqliteRow<'_> {} impl<'c> SqliteRow<'c> { diff --git a/sqlx-core/src/sqlite/value.rs b/sqlx-core/src/sqlite/value.rs index c8b1959c..70bcf1ce 100644 --- a/sqlx-core/src/sqlite/value.rs +++ b/sqlx-core/src/sqlite/value.rs @@ -31,7 +31,6 @@ impl<'c> SqliteValue<'c> { } fn r#type(&self) -> Option { - #[allow(unsafe_code)] let type_code = unsafe { sqlite3_column_type(self.statement.handle(), self.index) }; // SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL @@ -48,31 +47,21 @@ impl<'c> SqliteValue<'c> { /// Returns the 32-bit INTEGER result. pub(super) fn int(&self) -> i32 { - #[allow(unsafe_code)] - unsafe { - sqlite3_column_int(self.statement.handle(), self.index) - } + unsafe { sqlite3_column_int(self.statement.handle(), self.index) } } /// Returns the 64-bit INTEGER result. pub(super) fn int64(&self) -> i64 { - #[allow(unsafe_code)] - unsafe { - sqlite3_column_int64(self.statement.handle(), self.index) - } + unsafe { sqlite3_column_int64(self.statement.handle(), self.index) } } /// Returns the 64-bit, REAL result. pub(super) fn double(&self) -> f64 { - #[allow(unsafe_code)] - unsafe { - sqlite3_column_double(self.statement.handle(), self.index) - } + unsafe { sqlite3_column_double(self.statement.handle(), self.index) } } /// Returns the UTF-8 TEXT result. pub(super) fn text(&self) -> Option<&'c str> { - #[allow(unsafe_code)] unsafe { let ptr = sqlite3_column_text(self.statement.handle(), self.index) as *const i8; @@ -86,14 +75,12 @@ impl<'c> SqliteValue<'c> { fn bytes(&self) -> usize { // Returns the size of the result in bytes. - #[allow(unsafe_code)] let len = unsafe { sqlite3_column_bytes(self.statement.handle(), self.index) }; len as usize } /// Returns the BLOB result. pub(super) fn blob(&self) -> &'c [u8] { - #[allow(unsafe_code)] let ptr = unsafe { sqlite3_column_blob(self.statement.handle(), self.index) }; if ptr.is_null() { @@ -101,10 +88,7 @@ impl<'c> SqliteValue<'c> { return &[]; } - #[allow(unsafe_code)] - unsafe { - slice::from_raw_parts(ptr as *const u8, self.bytes()) - } + unsafe { slice::from_raw_parts(ptr as *const u8, self.bytes()) } } }