diff --git a/libsqlite3-sys/src/lib.rs b/libsqlite3-sys/src/lib.rs index 795d604..7b169b6 100644 --- a/libsqlite3-sys/src/lib.rs +++ b/libsqlite3-sys/src/lib.rs @@ -8,7 +8,7 @@ use std::mem; mod error; pub fn SQLITE_STATIC() -> sqlite3_destructor_type { - Some(unsafe { mem::transmute(0isize) }) + None } pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type { diff --git a/src/error.rs b/src/error.rs index ef22f61..be64e0e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -142,7 +142,7 @@ impl PartialEq for Error { (Error::UnwindingPanic, Error::UnwindingPanic) => true, #[cfg(feature = "functions")] (Error::GetAuxWrongType, Error::GetAuxWrongType) => true, - (_, _) => false, + (..) => false, } } } @@ -261,7 +261,7 @@ impl error::Error for Error { "SQLite was compiled or configured for single-threaded use only" } Error::FromSqlConversionFailure(_, _, ref err) => err.description(), - Error::IntegralValueOutOfRange(_, _) => "integral value out of range of requested type", + Error::IntegralValueOutOfRange(..) => "integral value out of range of requested type", Error::Utf8Error(ref err) => err.description(), Error::InvalidParameterName(_) => "invalid parameter name", Error::NulError(ref err) => err.description(), @@ -272,13 +272,13 @@ impl error::Error for Error { Error::QueryReturnedNoRows => "query returned no rows", Error::InvalidColumnIndex(_) => "invalid column index", Error::InvalidColumnName(_) => "invalid column name", - Error::InvalidColumnType(_, _, _) => "invalid column type", + Error::InvalidColumnType(..) => "invalid column type", Error::StatementChangedRows(_) => "query inserted zero or more than one row", #[cfg(feature = "functions")] - Error::InvalidFunctionParameterType(_, _) => "invalid function parameter type", + Error::InvalidFunctionParameterType(..) => "invalid function parameter type", #[cfg(feature = "vtab")] - Error::InvalidFilterParameterType(_, _) => "invalid filter parameter type", + Error::InvalidFilterParameterType(..) => "invalid filter parameter type", #[cfg(feature = "functions")] Error::UserFunctionError(ref err) => err.description(), Error::ToSqlConversionFailure(ref err) => err.description(), @@ -299,23 +299,23 @@ impl error::Error for Error { Error::Utf8Error(ref err) => Some(err), Error::NulError(ref err) => Some(err), - Error::IntegralValueOutOfRange(_, _) + Error::IntegralValueOutOfRange(..) | Error::SqliteSingleThreadedMode | Error::InvalidParameterName(_) | Error::ExecuteReturnedResults | Error::QueryReturnedNoRows | Error::InvalidColumnIndex(_) | Error::InvalidColumnName(_) - | Error::InvalidColumnType(_, _, _) + | Error::InvalidColumnType(..) | Error::InvalidPath(_) | Error::StatementChangedRows(_) | Error::InvalidQuery | Error::MultipleStatement => None, #[cfg(feature = "functions")] - Error::InvalidFunctionParameterType(_, _) => None, + Error::InvalidFunctionParameterType(..) => None, #[cfg(feature = "vtab")] - Error::InvalidFilterParameterType(_, _) => None, + Error::InvalidFilterParameterType(..) => None, #[cfg(feature = "functions")] Error::UserFunctionError(ref err) => Some(&**err), diff --git a/src/inner_connection.rs b/src/inner_connection.rs index 00675e2..d5d4e25 100644 --- a/src/inner_connection.rs +++ b/src/inner_connection.rs @@ -92,7 +92,7 @@ impl InnerConnection { if let Error::SqliteFailure( ffi::Error { code: ffi::ErrorCode::CannotOpen, - extended_code: _, + .. }, Some(msg), ) = e diff --git a/src/lib.rs b/src/lib.rs index 68ae770..bf7c1c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -701,7 +701,11 @@ impl Connection { /// /// You should not need to use this function. If you do need to, please /// [open an issue on the rusqlite repository](https://github.com/jgallagher/rusqlite/issues) and describe - /// your use case. This function is unsafe because it gives you raw access + /// your use case. + /// + /// # Safety + /// + /// This function is unsafe because it gives you raw access /// to the SQLite connection, and what you do with it could impact the /// safety of this `Connection`. pub unsafe fn handle(&self) -> *mut ffi::sqlite3 { @@ -797,8 +801,11 @@ impl Default for OpenFlags { /// If you are encountering that panic _and_ can ensure that SQLite has been /// initialized in either multi-thread or serialized mode, call this function /// prior to attempting to open a connection and rusqlite's initialization -/// process will by skipped. This -/// function is unsafe because if you call it and SQLite has actually been +/// process will by skipped. +/// +/// # Safety +/// +/// This function is unsafe because if you call it and SQLite has actually been /// configured to run in single-thread mode, /// you may enounter memory errors or data corruption or any number of terrible /// things that should not be possible when you're using Rust. @@ -809,11 +816,13 @@ pub unsafe fn bypass_sqlite_initialization() { /// rusqlite performs a one-time check that the runtime SQLite version is at /// least as new as the version of SQLite found when rusqlite was built. /// Bypassing this check may be dangerous; e.g., if you use features of SQLite -/// that are not present in the runtime -/// version. If you are sure the runtime version is compatible with the +/// that are not present in the runtime version. +/// +/// # Safety +/// +/// If you are sure the runtime version is compatible with the /// build-time version for your usage, you can bypass the version check by -/// calling this function before -/// your first connection attempt. +/// calling this function before your first connection attempt. pub unsafe fn bypass_sqlite_version_check() { #[cfg(not(feature = "bundled"))] inner_connection::BYPASS_VERSION_CHECK.store(true, Ordering::Relaxed); @@ -992,10 +1001,11 @@ mod test { let raw_db = db.db.borrow_mut().db; let sql = "SELECT 1"; let mut raw_stmt = MaybeUninit::uninit(); + let cstring = str_to_cstring(sql).unwrap(); let rc = unsafe { ffi::sqlite3_prepare_v2( raw_db, - str_to_cstring(sql).unwrap().as_ptr(), + cstring.as_ptr(), (sql.len() + 1) as c_int, raw_stmt.as_mut_ptr(), ptr::null_mut(), @@ -1511,7 +1521,7 @@ mod test { .collect(); match bad_type.unwrap_err() { - Error::InvalidColumnType(_, _, _) => (), + Error::InvalidColumnType(..) => (), err => panic!("Unexpected error {}", err), } @@ -1566,7 +1576,7 @@ mod test { .collect(); match bad_type.unwrap_err() { - CustomError::Sqlite(Error::InvalidColumnType(_, _, _)) => (), + CustomError::Sqlite(Error::InvalidColumnType(..)) => (), err => panic!("Unexpected error {}", err), } @@ -1623,7 +1633,7 @@ mod test { }); match bad_type.unwrap_err() { - CustomError::Sqlite(Error::InvalidColumnType(_, _, _)) => (), + CustomError::Sqlite(Error::InvalidColumnType(..)) => (), err => panic!("Unexpected error {}", err), } diff --git a/src/statement.rs b/src/statement.rs index f866c9f..5533897 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -1051,7 +1051,7 @@ mod test { use std::collections::BTreeSet; let data: BTreeSet = ["one", "two", "three"] .iter() - .map(|s| s.to_string()) + .map(|s| (*s).to_string()) .collect(); db.query_row("SELECT ?1, ?2, ?3", &data, |row| row.get::<_, String>(0)) .unwrap(); diff --git a/src/trace.rs b/src/trace.rs index 572b21f..1ccc55f 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -12,6 +12,9 @@ use crate::error::error_from_sqlite_code; use crate::{Connection, Result}; /// Set up the process-wide SQLite error logging callback. +/// +/// # Safety +/// /// This function is marked unsafe for two reasons: /// /// * The function is not threadsafe. No other SQLite calls may be made while diff --git a/src/types/from_sql.rs b/src/types/from_sql.rs index e621570..8da525c 100644 --- a/src/types/from_sql.rs +++ b/src/types/from_sql.rs @@ -36,7 +36,7 @@ impl PartialEq for FromSqlError { (FromSqlError::InvalidI128Size(s1), FromSqlError::InvalidI128Size(s2)) => s1 == s2, #[cfg(feature = "uuid")] (FromSqlError::InvalidUuidSize(s1), FromSqlError::InvalidUuidSize(s2)) => s1 == s2, - (_, _) => false, + (..) => false, } } } diff --git a/src/types/mod.rs b/src/types/mod.rs index 493dbeb..93214cc 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -225,7 +225,7 @@ mod test { fn test_mismatched_types() { fn is_invalid_column_type(err: Error) -> bool { match err { - Error::InvalidColumnType(_, _, _) => true, + Error::InvalidColumnType(..) => true, _ => false, } } diff --git a/src/vtab/mod.rs b/src/vtab/mod.rs index 5ec10ca..e5f7365 100644 --- a/src/vtab/mod.rs +++ b/src/vtab/mod.rs @@ -162,7 +162,11 @@ impl VTabConnection { /// /// You should not need to use this function. If you do need to, please /// [open an issue on the rusqlite repository](https://github.com/jgallagher/rusqlite/issues) and describe - /// your use case. This function is unsafe because it gives you raw access + /// your use case. + /// + /// # Safety + /// + /// This function is unsafe because it gives you raw access /// to the SQLite connection, and what you do with it could impact the /// safety of this `Connection`. pub unsafe fn handle(&mut self) -> *mut ffi::sqlite3 {