From 994d40da26ccf97a22981567bbae96886c426cdb Mon Sep 17 00:00:00 2001 From: gwenn Date: Fri, 4 May 2018 19:55:55 +0200 Subject: [PATCH] Fix clippy warnings --- appveyor.yml | 4 ++-- libsqlite3-sys/src/error.rs | 2 +- src/backup.rs | 2 +- src/blob.rs | 8 ++++---- src/cache.rs | 2 +- src/functions.rs | 19 +++++++++---------- src/hooks.rs | 7 +++---- src/lib.rs | 2 +- src/load_extension_guard.rs | 2 +- src/row.rs | 6 +++--- src/statement.rs | 4 ++-- src/transaction.rs | 8 ++++---- src/types/time.rs | 2 +- 13 files changed, 33 insertions(+), 35 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 155f6e7..3a7c0a7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,8 +1,8 @@ environment: matrix: - - TARGET: 1.24.1-x86_64-pc-windows-gnu + - TARGET: 1.25.0-x86_64-pc-windows-gnu MSYS2_BITS: 64 - - TARGET: 1.24.1-x86_64-pc-windows-msvc + - TARGET: 1.25.0-x86_64-pc-windows-msvc VCPKG_DEFAULT_TRIPLET: x64-windows VCPKGRS_DYNAMIC: 1 - TARGET: nightly-x86_64-pc-windows-msvc diff --git a/libsqlite3-sys/src/error.rs b/libsqlite3-sys/src/error.rs index 61c80f9..236ad90 100644 --- a/libsqlite3-sys/src/error.rs +++ b/libsqlite3-sys/src/error.rs @@ -91,7 +91,7 @@ impl Error { }; Error { - code: code, + code, extended_code: result_code, } } diff --git a/src/backup.rs b/src/backup.rs index 73ed119..96bbc45 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -208,7 +208,7 @@ impl<'a, 'b> Backup<'a, 'b> { Ok(Backup { phantom_from: PhantomData, phantom_to: PhantomData, - b: b, + b, }) } diff --git a/src/blob.rs b/src/blob.rs index a2b7ca8..1f020f4 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -95,7 +95,7 @@ impl Connection { .map(|_| { Blob { conn: self, - blob: blob, + blob, pos: 0, } }) @@ -205,14 +205,14 @@ impl<'conn> io::Seek for Blob<'conn> { fn seek(&mut self, pos: io::SeekFrom) -> io::Result { let pos = match pos { io::SeekFrom::Start(offset) => offset as i64, - io::SeekFrom::Current(offset) => self.pos as i64 + offset, - io::SeekFrom::End(offset) => self.size() as i64 + offset, + io::SeekFrom::Current(offset) => i64::from(self.pos) + offset, + io::SeekFrom::End(offset) => i64::from(self.size()) + offset, }; if pos < 0 { Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid seek to negative position")) - } else if pos > self.size() as i64 { + } else if pos > i64::from(self.size()) { Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid seek to position past end of blob")) } else { diff --git a/src/cache.rs b/src/cache.rs index d5bb5b4..86db9e3 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -92,7 +92,7 @@ impl<'conn> CachedStatement<'conn> { fn new(stmt: Statement<'conn>, cache: &'conn StatementCache) -> CachedStatement<'conn> { CachedStatement { stmt: Some(stmt), - cache: cache, + cache, } } diff --git a/src/functions.rs b/src/functions.rs index 0f792d2..a79b3e6 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -51,7 +51,6 @@ //! ``` use std::error::Error as StdError; use std::ffi::CStr; -use std::mem; use std::ptr; use std::slice; use std::os::raw::{c_int, c_char, c_void}; @@ -183,7 +182,7 @@ impl<'a> ValueRef<'a> { } unsafe extern "C" fn free_boxed_value(p: *mut c_void) { - let _: Box = Box::from_raw(mem::transmute(p)); + let _: Box = Box::from_raw(p as *mut T); } /// Context is a wrapper for the SQLite function evaluation context. @@ -234,7 +233,7 @@ impl<'a> Context<'a> { unsafe { ffi::sqlite3_set_auxdata(self.ctx, arg, - mem::transmute(boxed), + boxed as *mut c_void, Some(free_boxed_value::)) }; } @@ -370,10 +369,10 @@ impl InnerConnection { T: ToSql { let ctx = Context { - ctx: ctx, + ctx, args: slice::from_raw_parts(argv, argc as usize), }; - let boxed_f: *mut F = mem::transmute(ffi::sqlite3_user_data(ctx.ctx)); + let boxed_f: *mut F = ffi::sqlite3_user_data(ctx.ctx) as *mut F; assert!(!boxed_f.is_null(), "Internal error - null function pointer"); let t = (*boxed_f)(&ctx); @@ -397,7 +396,7 @@ impl InnerConnection { c_name.as_ptr(), n_arg, flags, - mem::transmute(boxed_f), + boxed_f as *mut c_void, Some(call_boxed_closure::), None, None, @@ -431,7 +430,7 @@ impl InnerConnection { where D: Aggregate, T: ToSql { - let boxed_aggr: *mut D = mem::transmute(ffi::sqlite3_user_data(ctx)); + let boxed_aggr: *mut D = ffi::sqlite3_user_data(ctx) as *mut D; assert!(!boxed_aggr.is_null(), "Internal error - null aggregate pointer"); @@ -448,7 +447,7 @@ impl InnerConnection { } let mut ctx = Context { - ctx: ctx, + ctx, args: slice::from_raw_parts(argv, argc as usize), }; @@ -462,7 +461,7 @@ impl InnerConnection { where D: Aggregate, T: ToSql { - let boxed_aggr: *mut D = mem::transmute(ffi::sqlite3_user_data(ctx)); + let boxed_aggr: *mut D = ffi::sqlite3_user_data(ctx) as *mut D; assert!(!boxed_aggr.is_null(), "Internal error - null aggregate pointer"); @@ -500,7 +499,7 @@ impl InnerConnection { c_name.as_ptr(), n_arg, flags, - mem::transmute(boxed_aggr), + boxed_aggr as *mut c_void, None, Some(call_boxed_step::), Some(call_boxed_final::), diff --git a/src/hooks.rs b/src/hooks.rs index 4bf0a59..86f4807 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -1,7 +1,6 @@ //! Commit, Data Change and Rollback Notification Callbacks #![allow(non_camel_case_types)] -use std::mem; use std::ptr; use std::os::raw::{c_int, c_char, c_void}; @@ -154,7 +153,7 @@ impl InnerConnection { unsafe extern "C" fn call_boxed_closure(p_arg: *mut c_void) -> c_int where F: FnMut() -> bool { - let boxed_hook: *mut F = mem::transmute(p_arg); + let boxed_hook: *mut F = p_arg as *mut F; assert!(!boxed_hook.is_null(), "Internal error - null function pointer"); @@ -178,7 +177,7 @@ impl InnerConnection { unsafe extern "C" fn call_boxed_closure(p_arg: *mut c_void) where F: FnMut() { - let boxed_hook: *mut F = mem::transmute(p_arg); + let boxed_hook: *mut F = p_arg as *mut F; assert!(!boxed_hook.is_null(), "Internal error - null function pointer"); @@ -209,7 +208,7 @@ impl InnerConnection { use std::ffi::CStr; use std::str; - let boxed_hook: *mut F = mem::transmute(p_arg); + let boxed_hook: *mut F = p_arg as *mut F; assert!(!boxed_hook.is_null(), "Internal error - null function pointer"); diff --git a/src/lib.rs b/src/lib.rs index 98e62da..13b659e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -779,7 +779,7 @@ impl InnerConnection { // attempt to turn on extended results code; don't fail if we can't. ffi::sqlite3_extended_result_codes(db, 1); - Ok(InnerConnection { db: db }) + Ok(InnerConnection { db }) } } diff --git a/src/load_extension_guard.rs b/src/load_extension_guard.rs index 7f62a60..d18a1e1 100644 --- a/src/load_extension_guard.rs +++ b/src/load_extension_guard.rs @@ -26,7 +26,7 @@ impl<'conn> LoadExtensionGuard<'conn> { /// guard goes out of scope. Cannot be meaningfully nested. pub fn new(conn: &Connection) -> Result { conn.load_extension_enable() - .map(|_| LoadExtensionGuard { conn: conn }) + .map(|_| LoadExtensionGuard { conn }) } } diff --git a/src/row.rs b/src/row.rs index 6ab0619..2042616 100644 --- a/src/row.rs +++ b/src/row.rs @@ -32,7 +32,7 @@ impl<'stmt> Rows<'stmt> { .and_then(|stmt| match stmt.step() { Ok(true) => { Some(Ok(Row { - stmt: stmt, + stmt, phantom: PhantomData, })) } @@ -90,7 +90,7 @@ impl<'stmt, T, F> MappedRowsCrateImpl<'stmt, T, F> for MappedRows<'stmt, F> where F: FnMut(&Row) -> T { fn new(rows: Rows<'stmt>, f: F) -> MappedRows<'stmt, F> { - MappedRows { rows: rows, map: f } + MappedRows { rows, map: f } } } @@ -124,7 +124,7 @@ impl<'stmt, T, E, F> AndThenRowsCrateImpl<'stmt, T, E, F> for AndThenRows<'stmt, where F: FnMut(&Row) -> result::Result { fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F> { - AndThenRows { rows: rows, map: f } + AndThenRows { rows, map: f } } } diff --git a/src/statement.rs b/src/statement.rs index 09c3bc3..c867ad4 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -506,8 +506,8 @@ pub trait StatementCrateImpl<'conn> { impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> { fn new(conn: &Connection, stmt: RawStatement) -> Statement { Statement { - conn: conn, - stmt: stmt, + conn, + stmt, } } diff --git a/src/transaction.rs b/src/transaction.rs index dd0807c..3b4509a 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -109,7 +109,7 @@ impl<'conn> Transaction<'conn> { conn.execute_batch(query) .map(move |_| { Transaction { - conn: conn, + conn, drop_behavior: DropBehavior::Rollback, committed: false, } @@ -227,9 +227,9 @@ impl<'conn> Savepoint<'conn> { conn.execute_batch(&format!("SAVEPOINT {}", name)) .map(|_| { Savepoint { - conn: conn, - name: name, - depth: depth, + conn, + name, + depth, drop_behavior: DropBehavior::Rollback, committed: false, } diff --git a/src/types/time.rs b/src/types/time.rs index 458435c..71a7955 100644 --- a/src/types/time.rs +++ b/src/types/time.rs @@ -24,7 +24,7 @@ impl FromSql for time::Timespec { time::strptime(s, SQLITE_DATETIME_FMT) .or_else(|err| { time::strptime(s, SQLITE_DATETIME_FMT_LEGACY) - .or(Err(FromSqlError::Other(Box::new(err))))})}) + .or_else(|_| Err(FromSqlError::Other(Box::new(err))))})}) .map(|tm| tm.to_timespec()) } }