Address additional clippy warnings

This commit is contained in:
John Gallagher 2016-03-29 14:18:56 -04:00
parent 2bd54578f5
commit 41fe698cec
5 changed files with 20 additions and 14 deletions

View File

@ -140,6 +140,7 @@ impl error::Error for Error {
} }
} }
#[allow(match_same_arms)]
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&error::Error> {
match *self { match *self {
Error::SqliteFailure(ref err, _) => Some(err), Error::SqliteFailure(ref err, _) => Some(err),
@ -159,6 +160,7 @@ impl error::Error for Error {
#[cfg(feature = "functions")] #[cfg(feature = "functions")]
Error::InvalidFunctionParameterType => None, Error::InvalidFunctionParameterType => None,
#[cfg(feature = "functions")] #[cfg(feature = "functions")]
Error::UserFunctionError(ref err) => Some(&**err), Error::UserFunctionError(ref err) => Some(&**err),
} }

View File

@ -307,7 +307,7 @@ impl<'a> Context<'a> {
ffi::sqlite3_set_auxdata(self.ctx, ffi::sqlite3_set_auxdata(self.ctx,
arg, arg,
mem::transmute(boxed), mem::transmute(boxed),
Some(mem::transmute(free_boxed_value::<T>))) Some(free_boxed_value::<T>))
}; };
} }
@ -480,7 +480,7 @@ impl InnerConnection {
Some(call_boxed_closure::<F, T>), Some(call_boxed_closure::<F, T>),
None, None,
None, None,
Some(mem::transmute(free_boxed_value::<F>))) Some(free_boxed_value::<F>))
}; };
self.decode_result(r) self.decode_result(r)
} }
@ -597,7 +597,7 @@ impl InnerConnection {
None, None,
Some(call_boxed_step::<A, D, T>), Some(call_boxed_step::<A, D, T>),
Some(call_boxed_final::<A, D, T>), Some(call_boxed_final::<A, D, T>),
Some(mem::transmute(free_boxed_value::<D>))) Some(free_boxed_value::<D>))
}; };
self.decode_result(r) self.decode_result(r)
} }
@ -626,6 +626,7 @@ mod test {
use std::collections::HashMap; use std::collections::HashMap;
use libc::c_double; use libc::c_double;
use self::regex::Regex; use self::regex::Regex;
use std::f64::EPSILON;
use {Connection, Error, Result}; use {Connection, Error, Result};
use functions::{Aggregate, Context}; use functions::{Aggregate, Context};
@ -642,7 +643,7 @@ mod test {
db.create_scalar_function("half", 1, true, half).unwrap(); db.create_scalar_function("half", 1, true, half).unwrap();
let result: Result<f64> = db.query_row("SELECT half(6)", &[], |r| r.get(0)); let result: Result<f64> = db.query_row("SELECT half(6)", &[], |r| r.get(0));
assert_eq!(3f64, result.unwrap()); assert!((3f64 - result.unwrap()).abs() < EPSILON);
} }
#[test] #[test]
@ -650,7 +651,7 @@ mod test {
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
db.create_scalar_function("half", 1, true, half).unwrap(); db.create_scalar_function("half", 1, true, half).unwrap();
let result: Result<f64> = db.query_row("SELECT half(6)", &[], |r| r.get(0)); let result: Result<f64> = db.query_row("SELECT half(6)", &[], |r| r.get(0));
assert_eq!(3f64, result.unwrap()); assert!((3f64 - result.unwrap()).abs() < EPSILON);
db.remove_function("half", 1).unwrap(); db.remove_function("half", 1).unwrap();
let result: Result<f64> = db.query_row("SELECT half(6)", &[], |r| r.get(0)); let result: Result<f64> = db.query_row("SELECT half(6)", &[], |r| r.get(0));

View File

@ -53,9 +53,6 @@
#![cfg_attr(feature="clippy", feature(plugin))] #![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))] #![cfg_attr(feature="clippy", plugin(clippy))]
// Clippy complains about SQLite in our doc comments, but they're fine.
#![cfg_attr(feature="clippy", allow(doc_markdown))]
extern crate libc; extern crate libc;
extern crate libsqlite3_sys as ffi; extern crate libsqlite3_sys as ffi;
#[macro_use] #[macro_use]
@ -1224,10 +1221,9 @@ mod test {
#[test] #[test]
fn test_open_with_flags() { fn test_open_with_flags() {
for bad_flags in [OpenFlags::empty(), for bad_flags in &[OpenFlags::empty(),
SQLITE_OPEN_READ_ONLY | SQLITE_OPEN_READ_WRITE, SQLITE_OPEN_READ_ONLY | SQLITE_OPEN_READ_WRITE,
SQLITE_OPEN_READ_ONLY | SQLITE_OPEN_CREATE] SQLITE_OPEN_READ_ONLY | SQLITE_OPEN_CREATE] {
.iter() {
assert!(Connection::open_in_memory_with_flags(*bad_flags).is_err()); assert!(Connection::open_in_memory_with_flags(*bad_flags).is_err());
} }
} }

View File

@ -174,6 +174,7 @@ impl<'conn> Drop for Transaction<'conn> {
} }
#[cfg(test)] #[cfg(test)]
#[cfg_attr(feature="clippy", allow(similar_names))]
mod test { mod test {
use Connection; use Connection;

View File

@ -328,11 +328,13 @@ impl FromSql for Value {
} }
#[cfg(test)] #[cfg(test)]
#[cfg_attr(feature="clippy", allow(similar_names))]
mod test { mod test {
use Connection; use Connection;
use super::time; use super::time;
use Error; use Error;
use libc::{c_int, c_double}; use libc::{c_int, c_double};
use std::f64::EPSILON;
fn checked_memory_handle() -> Connection { fn checked_memory_handle() -> Connection {
let db = Connection::open_in_memory().unwrap(); let db = Connection::open_in_memory().unwrap();
@ -403,6 +405,7 @@ mod test {
} }
#[test] #[test]
#[cfg_attr(feature="clippy", allow(cyclomatic_complexity))]
fn test_mismatched_types() { fn test_mismatched_types() {
fn is_invalid_column_type(err: Error) -> bool { fn is_invalid_column_type(err: Error) -> bool {
match err { match err {
@ -426,7 +429,7 @@ mod test {
assert_eq!(vec![1, 2], row.get_checked::<i32, Vec<u8>>(0).unwrap()); assert_eq!(vec![1, 2], row.get_checked::<i32, Vec<u8>>(0).unwrap());
assert_eq!("text", row.get_checked::<i32, String>(1).unwrap()); assert_eq!("text", row.get_checked::<i32, String>(1).unwrap());
assert_eq!(1, row.get_checked::<i32, c_int>(2).unwrap()); assert_eq!(1, row.get_checked::<i32, c_int>(2).unwrap());
assert_eq!(1.5, row.get_checked::<i32, c_double>(3).unwrap()); assert!((1.5 - row.get_checked::<i32, c_double>(3).unwrap()).abs() < EPSILON);
assert!(row.get_checked::<i32, Option<c_int>>(4).unwrap().is_none()); assert!(row.get_checked::<i32, Option<c_int>>(4).unwrap().is_none());
assert!(row.get_checked::<i32, Option<c_double>>(4).unwrap().is_none()); assert!(row.get_checked::<i32, Option<c_double>>(4).unwrap().is_none());
assert!(row.get_checked::<i32, Option<String>>(4).unwrap().is_none()); assert!(row.get_checked::<i32, Option<String>>(4).unwrap().is_none());
@ -491,7 +494,10 @@ mod test {
assert_eq!(Value::Text(String::from("text")), assert_eq!(Value::Text(String::from("text")),
row.get_checked::<i32, Value>(1).unwrap()); row.get_checked::<i32, Value>(1).unwrap());
assert_eq!(Value::Integer(1), row.get_checked::<i32, Value>(2).unwrap()); assert_eq!(Value::Integer(1), row.get_checked::<i32, Value>(2).unwrap());
assert_eq!(Value::Real(1.5), row.get_checked::<i32, Value>(3).unwrap()); match row.get_checked::<i32, Value>(3).unwrap() {
Value::Real(val) => assert!((1.5 - val).abs() < EPSILON),
x => panic!("Invalid Value {:?}", x),
}
assert_eq!(Value::Null, row.get_checked::<i32, Value>(4).unwrap()); assert_eq!(Value::Null, row.get_checked::<i32, Value>(4).unwrap());
} }
} }