Fix some clippy lints

This commit is contained in:
Jonas Platte 2020-11-17 20:47:21 +01:00 committed by Austin Bonander
parent 672f724aac
commit 3c7c266eac
11 changed files with 25 additions and 32 deletions

View File

@ -3,7 +3,7 @@ use console::style;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::{Read, Write}; use std::io::{Read, Write};
const MIGRATION_FOLDER: &'static str = "migrations"; const MIGRATION_FOLDER: &str = "migrations";
pub struct Migration { pub struct Migration {
pub name: String, pub name: String,

View File

@ -54,7 +54,7 @@ impl<'a, T> Stream for TryAsyncStream<'a, T> {
pin_mut!(receiver); pin_mut!(receiver);
// then we check to see if we have anything to return // then we check to see if we have anything to return
return receiver.poll_next(cx); receiver.poll_next(cx)
} }
} }

View File

@ -122,6 +122,6 @@ impl Decode<'_, MySql> for i32 {
impl Decode<'_, MySql> for i64 { impl Decode<'_, MySql> for i64 {
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError> { fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError> {
int_decode(value)?.try_into().map_err(Into::into) int_decode(value)
} }
} }

View File

@ -145,6 +145,6 @@ impl Decode<'_, MySql> for u32 {
impl Decode<'_, MySql> for u64 { impl Decode<'_, MySql> for u64 {
fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError> { fn decode(value: MySqlValueRef<'_>) -> Result<Self, BoxDynError> {
uint_decode(value)?.try_into().map_err(Into::into) uint_decode(value)
} }
} }

View File

@ -33,7 +33,7 @@ pub struct PgArgumentBuffer {
patches: Vec<( patches: Vec<(
usize, // offset usize, // offset
usize, // argument index usize, // argument index
Box<dyn Fn(&mut [u8], &PgTypeInfo) -> () + 'static + Send + Sync>, Box<dyn Fn(&mut [u8], &PgTypeInfo) + 'static + Send + Sync>,
)>, )>,
// Whenever an `Encode` impl encounters a `PgTypeInfo` object that does not have an OID // Whenever an `Encode` impl encounters a `PgTypeInfo` object that does not have an OID

View File

@ -317,10 +317,10 @@ impl PgConnection {
} }
_ => { _ => {
Err(err_protocol!( return Err(err_protocol!(
"execute: unexpected message: {:?}", "execute: unexpected message: {:?}",
message.format message.format
))?; ));
} }
} }
} }

View File

@ -995,20 +995,18 @@ impl PartialEq<PgType> for PgType {
if let (Some(a), Some(b)) = (self.try_oid(), other.try_oid()) { if let (Some(a), Some(b)) = (self.try_oid(), other.try_oid()) {
// If there are OIDs available, use OIDs to perform a direct match // If there are OIDs available, use OIDs to perform a direct match
a == b a == b
} else if (matches!(self, PgType::DeclareWithName(_))
&& matches!(other, PgType::DeclareWithOid(_)))
|| (matches!(other, PgType::DeclareWithName(_))
&& matches!(self, PgType::DeclareWithOid(_)))
{
// One is a declare-with-name and the other is a declare-with-id
// This only occurs in the TEXT protocol with custom types
// Just opt-out of type checking here
true
} else { } else {
if (matches!(self, PgType::DeclareWithName(_)) // Otherwise, perform a match on the name
&& matches!(other, PgType::DeclareWithOid(_))) self.name().eq_ignore_ascii_case(other.name())
|| (matches!(other, PgType::DeclareWithName(_))
&& matches!(self, PgType::DeclareWithOid(_)))
{
// One is a declare-with-name and the other is a declare-with-id
// This only occurs in the TEXT protocol with custom types
// Just opt-out of type checking here
true
} else {
// Otherwise, perform a match on the name
self.name().eq_ignore_ascii_case(other.name())
}
} }
} }
} }

View File

@ -177,7 +177,7 @@ pub fn check_transparent_attributes(
Ok(attributes) Ok(attributes)
} }
pub fn check_enum_attributes<'a>(input: &'a DeriveInput) -> syn::Result<SqlxContainerAttributes> { pub fn check_enum_attributes(input: &DeriveInput) -> syn::Result<SqlxContainerAttributes> {
let attributes = parse_container_attributes(&input.attrs)?; let attributes = parse_container_attributes(&input.attrs)?;
assert_attribute!( assert_attribute!(

View File

@ -38,11 +38,9 @@ impl ToTokens for QuotedMigration {
// mostly copied from sqlx-core/src/migrate/source.rs // mostly copied from sqlx-core/src/migrate/source.rs
pub(crate) fn expand_migrator_from_dir(dir: LitStr) -> crate::Result<proc_macro2::TokenStream> { pub(crate) fn expand_migrator_from_dir(dir: LitStr) -> crate::Result<proc_macro2::TokenStream> {
let path = crate::common::resolve_path(&dir.value(), dir.span())?; let path = crate::common::resolve_path(&dir.value(), dir.span())?;
let mut s = fs::read_dir(path)?;
let mut migrations = Vec::new(); let mut migrations = Vec::new();
while let Some(entry) = s.next() { for entry in fs::read_dir(path)? {
let entry = entry?; let entry = entry?;
if !entry.metadata()?.is_file() { if !entry.metadata()?.is_file() {
// not a file; ignore // not a file; ignore

View File

@ -86,7 +86,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result<TokenSt
}, },
#[cfg(not(feature = "postgres"))] #[cfg(not(feature = "postgres"))]
"postgres" | "postgresql" => Err(format!("database URL has the scheme of a PostgreSQL database but the `postgres` feature is not enabled").into()), "postgres" | "postgresql" => Err("database URL has the scheme of a PostgreSQL database but the `postgres` feature is not enabled".into()),
#[cfg(feature = "mssql")] #[cfg(feature = "mssql")]
"mssql" | "sqlserver" => { "mssql" | "sqlserver" => {
@ -99,7 +99,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result<TokenSt
}, },
#[cfg(not(feature = "mssql"))] #[cfg(not(feature = "mssql"))]
"mssql" | "sqlserver" => Err(format!("database URL has the scheme of a MSSQL database but the `mssql` feature is not enabled").into()), "mssql" | "sqlserver" => Err("database URL has the scheme of a MSSQL database but the `mssql` feature is not enabled".into()),
#[cfg(feature = "mysql")] #[cfg(feature = "mysql")]
"mysql" | "mariadb" => { "mysql" | "mariadb" => {
@ -112,7 +112,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result<TokenSt
}, },
#[cfg(not(feature = "mysql"))] #[cfg(not(feature = "mysql"))]
"mysql" | "mariadb" => Err(format!("database URL has the scheme of a MySQL/MariaDB database but the `mysql` feature is not enabled").into()), "mysql" | "mariadb" => Err("database URL has the scheme of a MySQL/MariaDB database but the `mysql` feature is not enabled".into()),
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
"sqlite" => { "sqlite" => {
@ -125,7 +125,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result<TokenSt
}, },
#[cfg(not(feature = "sqlite"))] #[cfg(not(feature = "sqlite"))]
"sqlite" => Err(format!("database URL has the scheme of a SQLite database but the `sqlite` feature is not enabled").into()), "sqlite" => Err("database URL has the scheme of a SQLite database but the `sqlite` feature is not enabled".into()),
scheme => Err(format!("unknown database URL scheme {:?}", scheme).into()) scheme => Err(format!("unknown database URL scheme {:?}", scheme).into())
} }

View File

@ -25,10 +25,7 @@ pub(super) enum ColumnType {
impl ColumnType { impl ColumnType {
pub(super) fn is_wildcard(&self) -> bool { pub(super) fn is_wildcard(&self) -> bool {
match self { !matches!(self, ColumnType::Exact(_))
ColumnType::Exact(_) => false,
_ => true,
}
} }
} }