From ce90b519bb9946bf1cbab77479bb92d0fbc467c0 Mon Sep 17 00:00:00 2001 From: gwenn Date: Fri, 1 Oct 2021 20:09:48 +0200 Subject: [PATCH] Fix clippy warnings --- libsqlite3-sys/build.rs | 21 ++++++++++----------- src/inner_connection.rs | 4 +--- src/lib.rs | 10 ++++++---- src/row.rs | 4 ++-- src/statement.rs | 2 +- src/vtab/mod.rs | 4 ++-- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index d6b2b7e..9f59567 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -85,10 +85,9 @@ mod build_bundled { pub fn main(out_dir: &str, out_path: &Path) { let lib_name = super::lib_name(); - if cfg!(feature = "bundled-windows") && !cfg!(feature = "bundled") && !win_target() { - // This is just a sanity check, the top level `main` should ensure this. - panic!("This module should not be used: we're not on Windows and the bundled feature has not been enabled"); - } + // This is just a sanity check, the top level `main` should ensure this. + assert!(!(cfg!(feature = "bundled-windows") && !cfg!(feature = "bundled") && !win_target()), + "This module should not be used: we're not on Windows and the bundled feature has not been enabled"); #[cfg(feature = "buildtime_bindgen")] { @@ -159,12 +158,11 @@ mod build_bundled { let lib_dir = lib_dir.unwrap_or_else(|| openssl_dir.join("lib")); let inc_dir = inc_dir.unwrap_or_else(|| openssl_dir.join("include")); - if !Path::new(&lib_dir).exists() { - panic!( - "OpenSSL library directory does not exist: {}", - lib_dir.to_string_lossy() - ); - } + assert!( + Path::new(&lib_dir).exists(), + "OpenSSL library directory does not exist: {}", + lib_dir.to_string_lossy() + ); if !Path::new(&inc_dir).exists() { panic!( @@ -221,7 +219,8 @@ mod build_bundled { cfg.flag("-fsanitize=address"); } - // If explicitly requested: enable static linking against the Microsoft Visual C++ Runtime to avoid dependencies on vcruntime140.dll and similar libraries. + // If explicitly requested: enable static linking against the Microsoft Visual + // C++ Runtime to avoid dependencies on vcruntime140.dll and similar libraries. if cfg!(target_feature = "crt-static") && is_compiler("msvc") { cfg.static_crt(true); } diff --git a/src/inner_connection.rs b/src/inner_connection.rs index c632dd9..d03d04a 100644 --- a/src/inner_connection.rs +++ b/src/inner_connection.rs @@ -430,15 +430,13 @@ fn ensure_safe_sqlite_threading_mode() -> Result<()> { } unsafe { - if ffi::sqlite3_config(ffi::SQLITE_CONFIG_MULTITHREAD) != ffi::SQLITE_OK || ffi::sqlite3_initialize() != ffi::SQLITE_OK { - panic!( + assert!(ffi::sqlite3_config(ffi::SQLITE_CONFIG_MULTITHREAD) == ffi::SQLITE_OK && ffi::sqlite3_initialize() == ffi::SQLITE_OK, "Could not ensure safe initialization of SQLite.\n\ To fix this, either:\n\ * Upgrade SQLite to at least version 3.7.0\n\ * Ensure that SQLite has been initialized in Multi-thread or Serialized mode and call\n\ rusqlite::bypass_sqlite_initialization() prior to your first connection attempt." ); - } } }); Ok(()) diff --git a/src/lib.rs b/src/lib.rs index a606c60..d026337 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -679,7 +679,7 @@ impl Connection { stmt.check_no_tail()?; let mut rows = stmt.query(params)?; - rows.get_expected_row().map_err(E::from).and_then(|r| f(r)) + rows.get_expected_row().map_err(E::from).and_then(f) } /// Prepare a SQL statement for execution. @@ -1346,9 +1346,11 @@ mod test { fn test_execute_select() { let db = checked_memory_handle(); let err = db.execute("SELECT 1 WHERE 1 < ?", [1i32]).unwrap_err(); - if err != Error::ExecuteReturnedResults { - panic!("Unexpected error: {}", err); - } + assert!( + err == Error::ExecuteReturnedResults, + "Unexpected error: {}", + err + ); } #[test] diff --git a/src/row.rs b/src/row.rs index 89e6902..826aab9 100644 --- a/src/row.rs +++ b/src/row.rs @@ -156,7 +156,7 @@ where self.rows .next() .transpose() - .map(|row_result| row_result.and_then(|row| (map)(row))) + .map(|row_result| row_result.and_then(map)) } } @@ -181,7 +181,7 @@ where self.rows .next() .transpose() - .map(|row_result| row_result.map_err(E::from).and_then(|row| (map)(row))) + .map(|row_result| row_result.map_err(E::from).and_then(map)) } } diff --git a/src/statement.rs b/src/statement.rs index 0d80dd1..fd6df71 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -453,7 +453,7 @@ impl Statement<'_> { { let mut rows = self.query(params)?; - rows.get_expected_row().and_then(|r| f(r)) + rows.get_expected_row().and_then(f) } /// Convenience method to execute a query with named parameter(s) that is diff --git a/src/vtab/mod.rs b/src/vtab/mod.rs index 8398c47..cb26bcc 100644 --- a/src/vtab/mod.rs +++ b/src/vtab/mod.rs @@ -431,7 +431,7 @@ impl<'a> Iterator for IndexConstraintIter<'a> { #[inline] fn next(&mut self) -> Option> { - self.iter.next().map(|raw| IndexConstraint(raw)) + self.iter.next().map(IndexConstraint) } #[inline] @@ -492,7 +492,7 @@ impl<'a> Iterator for OrderByIter<'a> { #[inline] fn next(&mut self) -> Option> { - self.iter.next().map(|raw| OrderBy(raw)) + self.iter.next().map(OrderBy) } #[inline]