From 3c7c266eac339473ab7bda90c47bccf2f9b9a870 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 17 Nov 2020 20:47:21 +0100 Subject: [PATCH] Fix some clippy lints --- sqlx-cli/src/migration.rs | 2 +- sqlx-core/src/ext/async_stream.rs | 2 +- sqlx-core/src/mysql/types/int.rs | 2 +- sqlx-core/src/mysql/types/uint.rs | 2 +- sqlx-core/src/postgres/arguments.rs | 2 +- sqlx-core/src/postgres/connection/executor.rs | 4 ++-- sqlx-core/src/postgres/type_info.rs | 24 +++++++++---------- sqlx-macros/src/derives/attributes.rs | 2 +- sqlx-macros/src/migrate.rs | 4 +--- sqlx-macros/src/query/mod.rs | 8 +++---- sqlx-macros/src/query/output.rs | 5 +--- 11 files changed, 25 insertions(+), 32 deletions(-) diff --git a/sqlx-cli/src/migration.rs b/sqlx-cli/src/migration.rs index 7e9bd858..fa2b70fb 100644 --- a/sqlx-cli/src/migration.rs +++ b/sqlx-cli/src/migration.rs @@ -3,7 +3,7 @@ use console::style; use std::fs::{self, File}; use std::io::{Read, Write}; -const MIGRATION_FOLDER: &'static str = "migrations"; +const MIGRATION_FOLDER: &str = "migrations"; pub struct Migration { pub name: String, diff --git a/sqlx-core/src/ext/async_stream.rs b/sqlx-core/src/ext/async_stream.rs index af368c7b..a3926096 100644 --- a/sqlx-core/src/ext/async_stream.rs +++ b/sqlx-core/src/ext/async_stream.rs @@ -54,7 +54,7 @@ impl<'a, T> Stream for TryAsyncStream<'a, T> { pin_mut!(receiver); // then we check to see if we have anything to return - return receiver.poll_next(cx); + receiver.poll_next(cx) } } diff --git a/sqlx-core/src/mysql/types/int.rs b/sqlx-core/src/mysql/types/int.rs index 5884d30f..feff8626 100644 --- a/sqlx-core/src/mysql/types/int.rs +++ b/sqlx-core/src/mysql/types/int.rs @@ -122,6 +122,6 @@ impl Decode<'_, MySql> for i32 { impl Decode<'_, MySql> for i64 { fn decode(value: MySqlValueRef<'_>) -> Result { - int_decode(value)?.try_into().map_err(Into::into) + int_decode(value) } } diff --git a/sqlx-core/src/mysql/types/uint.rs b/sqlx-core/src/mysql/types/uint.rs index ba389fc5..1d7212a1 100644 --- a/sqlx-core/src/mysql/types/uint.rs +++ b/sqlx-core/src/mysql/types/uint.rs @@ -145,6 +145,6 @@ impl Decode<'_, MySql> for u32 { impl Decode<'_, MySql> for u64 { fn decode(value: MySqlValueRef<'_>) -> Result { - uint_decode(value)?.try_into().map_err(Into::into) + uint_decode(value) } } diff --git a/sqlx-core/src/postgres/arguments.rs b/sqlx-core/src/postgres/arguments.rs index ce5ea18b..9bd60dbb 100644 --- a/sqlx-core/src/postgres/arguments.rs +++ b/sqlx-core/src/postgres/arguments.rs @@ -33,7 +33,7 @@ pub struct PgArgumentBuffer { patches: Vec<( usize, // offset usize, // argument index - Box () + 'static + Send + Sync>, + Box, )>, // Whenever an `Encode` impl encounters a `PgTypeInfo` object that does not have an OID diff --git a/sqlx-core/src/postgres/connection/executor.rs b/sqlx-core/src/postgres/connection/executor.rs index fe0a5eb2..3b5ab3ef 100644 --- a/sqlx-core/src/postgres/connection/executor.rs +++ b/sqlx-core/src/postgres/connection/executor.rs @@ -317,10 +317,10 @@ impl PgConnection { } _ => { - Err(err_protocol!( + return Err(err_protocol!( "execute: unexpected message: {:?}", message.format - ))?; + )); } } } diff --git a/sqlx-core/src/postgres/type_info.rs b/sqlx-core/src/postgres/type_info.rs index 8a9f7caa..e74ca854 100644 --- a/sqlx-core/src/postgres/type_info.rs +++ b/sqlx-core/src/postgres/type_info.rs @@ -995,20 +995,18 @@ impl PartialEq for PgType { if let (Some(a), Some(b)) = (self.try_oid(), other.try_oid()) { // If there are OIDs available, use OIDs to perform a direct match 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 { - 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 { - // Otherwise, perform a match on the name - self.name().eq_ignore_ascii_case(other.name()) - } + // Otherwise, perform a match on the name + self.name().eq_ignore_ascii_case(other.name()) } } } diff --git a/sqlx-macros/src/derives/attributes.rs b/sqlx-macros/src/derives/attributes.rs index 4d2dadbb..5b454c96 100644 --- a/sqlx-macros/src/derives/attributes.rs +++ b/sqlx-macros/src/derives/attributes.rs @@ -177,7 +177,7 @@ pub fn check_transparent_attributes( Ok(attributes) } -pub fn check_enum_attributes<'a>(input: &'a DeriveInput) -> syn::Result { +pub fn check_enum_attributes(input: &DeriveInput) -> syn::Result { let attributes = parse_container_attributes(&input.attrs)?; assert_attribute!( diff --git a/sqlx-macros/src/migrate.rs b/sqlx-macros/src/migrate.rs index f39ba224..70e55675 100644 --- a/sqlx-macros/src/migrate.rs +++ b/sqlx-macros/src/migrate.rs @@ -38,11 +38,9 @@ impl ToTokens for QuotedMigration { // mostly copied from sqlx-core/src/migrate/source.rs pub(crate) fn expand_migrator_from_dir(dir: LitStr) -> crate::Result { let path = crate::common::resolve_path(&dir.value(), dir.span())?; - let mut s = fs::read_dir(path)?; - let mut migrations = Vec::new(); - while let Some(entry) = s.next() { + for entry in fs::read_dir(path)? { let entry = entry?; if !entry.metadata()?.is_file() { // not a file; ignore diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs index eb568b6f..35c26002 100644 --- a/sqlx-macros/src/query/mod.rs +++ b/sqlx-macros/src/query/mod.rs @@ -86,7 +86,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result 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")] "mssql" | "sqlserver" => { @@ -99,7 +99,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result 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")] "mysql" | "mariadb" => { @@ -112,7 +112,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result 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")] "sqlite" => { @@ -125,7 +125,7 @@ fn expand_from_db(input: QueryMacroInput, db_url: &str) -> crate::Result 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()) } diff --git a/sqlx-macros/src/query/output.rs b/sqlx-macros/src/query/output.rs index b7a7891a..84f91f6d 100644 --- a/sqlx-macros/src/query/output.rs +++ b/sqlx-macros/src/query/output.rs @@ -25,10 +25,7 @@ pub(super) enum ColumnType { impl ColumnType { pub(super) fn is_wildcard(&self) -> bool { - match self { - ColumnType::Exact(_) => false, - _ => true, - } + !matches!(self, ColumnType::Exact(_)) } }