From d229f0f9e9d74613a470a874beb19e53020ef7ab Mon Sep 17 00:00:00 2001 From: gwenn Date: Fri, 9 Aug 2019 20:01:44 +0200 Subject: [PATCH 1/3] Remove #[macro_use] attribute when importing macros --- src/busy.rs | 2 +- src/hooks.rs | 1 + src/lib.rs | 8 +------- src/session.rs | 2 +- src/trace.rs | 1 + src/vtab/array.rs | 2 +- src/vtab/csvtab.rs | 2 +- src/vtab/mod.rs | 2 +- src/vtab/series.rs | 4 ++-- tests/config_log.rs | 5 +---- 10 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/busy.rs b/src/busy.rs index f801e3f..b9bfc65 100644 --- a/src/busy.rs +++ b/src/busy.rs @@ -137,7 +137,7 @@ mod test { #[test] #[ignore] // FIXME: unstable fn test_busy_handler() { - lazy_static! { + lazy_static::lazy_static! { static ref CALLED: AtomicBool = AtomicBool::new(false); } fn busy_handler(_: i32) -> bool { diff --git a/src/hooks.rs b/src/hooks.rs index 3131462..946407a 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -237,6 +237,7 @@ mod test { use super::Action; use crate::Connection; use std::sync::atomic::{AtomicBool, Ordering}; + use lazy_static::lazy_static; #[test] fn test_commit_hook() { diff --git a/src/lib.rs b/src/lib.rs index d7883529..31c483c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,12 +58,6 @@ pub use libsqlite3_sys as ffi; -#[macro_use] -extern crate bitflags; -#[cfg(any(test, feature = "vtab"))] -#[macro_use] -extern crate lazy_static; - use std::cell::RefCell; use std::convert; use std::default::Default; @@ -761,7 +755,7 @@ impl fmt::Debug for Connection { } } -bitflags! { +bitflags::bitflags! { #[doc = "Flags for opening SQLite database connections."] #[doc = "See [sqlite3_open_v2](http://www.sqlite.org/c3ref/open.html) for details."] #[repr(C)] diff --git a/src/session.rs b/src/session.rs index 4ff88b6..bce3e1a 100644 --- a/src/session.rs +++ b/src/session.rs @@ -822,7 +822,7 @@ mod test { db.execute_batch("CREATE TABLE foo(t TEXT PRIMARY KEY NOT NULL);") .unwrap(); - lazy_static! { + lazy_static::lazy_static! { static ref CALLED: AtomicBool = AtomicBool::new(false); } db.apply( diff --git a/src/trace.rs b/src/trace.rs index 8af3f27..d6f3969 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -124,6 +124,7 @@ impl Connection { mod test { use std::sync::Mutex; use std::time::Duration; + use lazy_static::lazy_static; use crate::Connection; diff --git a/src/vtab/array.rs b/src/vtab/array.rs index 1b4bd46..5a572a1 100644 --- a/src/vtab/array.rs +++ b/src/vtab/array.rs @@ -35,7 +35,7 @@ pub fn load_module(conn: &Connection) -> Result<()> { conn.create_module("rarray", &ARRAY_MODULE, aux) } -lazy_static! { +lazy_static::lazy_static! { static ref ARRAY_MODULE: Module = eponymous_only_module::(1); } diff --git a/src/vtab/csvtab.rs b/src/vtab/csvtab.rs index bf092b0..acae3fc 100644 --- a/src/vtab/csvtab.rs +++ b/src/vtab/csvtab.rs @@ -32,7 +32,7 @@ pub fn load_module(conn: &Connection) -> Result<()> { conn.create_module("csv", &CSV_MODULE, aux) } -lazy_static! { +lazy_static::lazy_static! { static ref CSV_MODULE: Module = read_only_module::(1); } diff --git a/src/vtab/mod.rs b/src/vtab/mod.rs index 2a7191d..5ec10ca 100644 --- a/src/vtab/mod.rs +++ b/src/vtab/mod.rs @@ -234,7 +234,7 @@ pub trait CreateVTab: VTab { } } -bitflags! { +bitflags::bitflags! { #[doc = "Index constraint operator."] #[repr(C)] pub struct IndexConstraintOp: ::std::os::raw::c_uchar { diff --git a/src/vtab/series.rs b/src/vtab/series.rs index 722ed4b..c0d1100 100644 --- a/src/vtab/series.rs +++ b/src/vtab/series.rs @@ -18,7 +18,7 @@ pub fn load_module(conn: &Connection) -> Result<()> { conn.create_module("generate_series", &SERIES_MODULE, aux) } -lazy_static! { +lazy_static::lazy_static! { static ref SERIES_MODULE: Module = eponymous_only_module::(1); } @@ -28,7 +28,7 @@ const SERIES_COLUMN_START: c_int = 1; const SERIES_COLUMN_STOP: c_int = 2; const SERIES_COLUMN_STEP: c_int = 3; -bitflags! { +bitflags::bitflags! { #[repr(C)] struct QueryPlanFlags: ::std::os::raw::c_int { // start = $value -- constraint exists diff --git a/tests/config_log.rs b/tests/config_log.rs index d51acf5..aa90b94 100644 --- a/tests/config_log.rs +++ b/tests/config_log.rs @@ -2,14 +2,11 @@ //! function affects SQLite process-wide and so is not safe to run as a normal //! #[test] in the library. -#[cfg(feature = "trace")] -#[macro_use] -extern crate lazy_static; - #[cfg(feature = "trace")] fn main() { use std::os::raw::c_int; use std::sync::Mutex; + use lazy_static::lazy_static; lazy_static! { static ref LOGS_RECEIVED: Mutex> = Mutex::new(Vec::new()); From e4fecf7fb892279c97729323836cc1257627bb04 Mon Sep 17 00:00:00 2001 From: gwenn Date: Fri, 9 Aug 2019 20:03:46 +0200 Subject: [PATCH 2/3] Rustfmt --- libsqlite3-sys/build.rs | 10 ++++++---- src/error.rs | 37 +++++++++++++++++++++---------------- src/hooks.rs | 2 +- src/trace.rs | 2 +- tests/config_log.rs | 2 +- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index 2321c91..dee18af 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -74,11 +74,13 @@ mod build_bundled { .flag("-DSQLITE_THREADSAFE=1") .flag("-DSQLITE_USE_URI") .flag("-DHAVE_USLEEP=1"); - // Older versions of visual studio don't support c99 (including isnan), which causes a - // build failure when the linker fails to find the `isnan` function. `sqlite` provides its - // own implmentation, using the fact that x != x when x is NaN. + // Older versions of visual studio don't support c99 (including isnan), which + // causes a build failure when the linker fails to find the `isnan` + // function. `sqlite` provides its own implmentation, using the fact + // that x != x when x is NaN. // - // There may be other platforms that don't support `isnan`, they should be tested for here. + // There may be other platforms that don't support `isnan`, they should be + // tested for here. if cfg!(target_env = "msvc") { use self::cc::windows_registry::{find_vs_version, VsVers}; let vs_has_nan = match find_vs_version() { diff --git a/src/error.rs b/src/error.rs index abd4669..827c781 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,5 @@ -use crate::types::Type; use crate::types::FromSqlError; +use crate::types::Type; use crate::{errmsg_to_string, ffi}; use std::error; use std::fmt; @@ -162,7 +162,8 @@ const UNKNOWN_COLUMN: usize = std::usize::MAX; /// to allow use of `get_raw(…).as_…()?` in callbacks that take `Error`. impl From for Error { fn from(err: FromSqlError) -> Error { - // The error type requires index and type fields, but they aren't known in this context. + // The error type requires index and type fields, but they aren't known in this + // context. match err { FromSqlError::OutOfRange(val) => Error::IntegralValueOutOfRange(UNKNOWN_COLUMN, val), #[cfg(feature = "i128_blob")] @@ -190,20 +191,24 @@ impl fmt::Display for Error { f, "SQLite was compiled or configured for single-threaded use only" ), - Error::FromSqlConversionFailure(i, ref t, ref err) => if i != UNKNOWN_COLUMN { - write!( - f, - "Conversion error from type {} at index: {}, {}", - t, i, err - ) - } else { - err.fmt(f) - }, - Error::IntegralValueOutOfRange(col, val) => if col != UNKNOWN_COLUMN { - write!(f, "Integer {} out of range at index {}", val, col) - } else { - write!(f, "Integer {} out of range", val) - }, + Error::FromSqlConversionFailure(i, ref t, ref err) => { + if i != UNKNOWN_COLUMN { + write!( + f, + "Conversion error from type {} at index: {}, {}", + t, i, err + ) + } else { + err.fmt(f) + } + } + Error::IntegralValueOutOfRange(col, val) => { + if col != UNKNOWN_COLUMN { + write!(f, "Integer {} out of range at index {}", val, col) + } else { + write!(f, "Integer {} out of range", val) + } + } Error::Utf8Error(ref err) => err.fmt(f), Error::NulError(ref err) => err.fmt(f), Error::InvalidParameterName(ref name) => write!(f, "Invalid parameter name: {}", name), diff --git a/src/hooks.rs b/src/hooks.rs index 946407a..e8efe76 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -236,8 +236,8 @@ fn free_boxed_hook(p: *mut c_void) { mod test { use super::Action; use crate::Connection; - use std::sync::atomic::{AtomicBool, Ordering}; use lazy_static::lazy_static; + use std::sync::atomic::{AtomicBool, Ordering}; #[test] fn test_commit_hook() { diff --git a/src/trace.rs b/src/trace.rs index d6f3969..572b21f 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -122,9 +122,9 @@ impl Connection { #[cfg(test)] mod test { + use lazy_static::lazy_static; use std::sync::Mutex; use std::time::Duration; - use lazy_static::lazy_static; use crate::Connection; diff --git a/tests/config_log.rs b/tests/config_log.rs index aa90b94..0c28bdf 100644 --- a/tests/config_log.rs +++ b/tests/config_log.rs @@ -4,9 +4,9 @@ #[cfg(feature = "trace")] fn main() { + use lazy_static::lazy_static; use std::os::raw::c_int; use std::sync::Mutex; - use lazy_static::lazy_static; lazy_static! { static ref LOGS_RECEIVED: Mutex> = Mutex::new(Vec::new()); From dcc43fa4457771622388b478f8b6f304cb7879b1 Mon Sep 17 00:00:00 2001 From: gwenn Date: Fri, 9 Aug 2019 20:06:31 +0200 Subject: [PATCH 3/3] Fix warnings --- src/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 827c781..b932465 100644 --- a/src/error.rs +++ b/src/error.rs @@ -167,11 +167,11 @@ impl From for Error { match err { FromSqlError::OutOfRange(val) => Error::IntegralValueOutOfRange(UNKNOWN_COLUMN, val), #[cfg(feature = "i128_blob")] - FromSqlError::InvalidI128Size(s) => { + FromSqlError::InvalidI128Size(_) => { Error::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Blob, Box::new(err)) } #[cfg(feature = "uuid")] - FromSqlError::InvalidUuidSize(s) => { + FromSqlError::InvalidUuidSize(_) => { Error::FromSqlConversionFailure(UNKNOWN_COLUMN, Type::Blob, Box::new(err)) } FromSqlError::Other(source) => {