From 1227b934c8bdc08ef3cc8ae097c2319288af2f0a Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Fri, 19 Feb 2021 00:07:18 -0800 Subject: [PATCH] style(mysql): clippy --- sqlx-mysql/src/connection/flush.rs | 4 +-- sqlx-mysql/src/lib.rs | 6 ++-- sqlx-mysql/src/output.rs | 1 + sqlx-mysql/src/protocol/execute.rs | 20 +++++-------- sqlx-mysql/src/raw_value.rs | 3 +- sqlx-mysql/src/type_id.rs | 47 +++++++++++++++--------------- sqlx-mysql/src/type_info.rs | 1 + sqlx-mysql/src/types/uint.rs | 4 +-- 8 files changed, 44 insertions(+), 42 deletions(-) diff --git a/sqlx-mysql/src/connection/flush.rs b/sqlx-mysql/src/connection/flush.rs index ed31d3c7..f32964c3 100644 --- a/sqlx-mysql/src/connection/flush.rs +++ b/sqlx-mysql/src/connection/flush.rs @@ -74,7 +74,7 @@ macro_rules! impl_flush { continue; } - let _ = read_packet!($(@$blocking)? stream); + let _packet = read_packet!($(@$blocking)? stream); // STATE: now expecting the next parameter *cmd = PrepareCommand::ParameterDefinition { rem: *rem - 1, columns: *columns }; @@ -86,7 +86,7 @@ macro_rules! impl_flush { break commands.end(); } - let _ = read_packet!($(@$blocking)? stream); + let _packet = read_packet!($(@$blocking)? stream); // STATE: now expecting the next parameter *cmd = PrepareCommand::ColumnDefinition { rem: *rem - 1 }; diff --git a/sqlx-mysql/src/lib.rs b/sqlx-mysql/src/lib.rs index dc56c016..c7a16e8c 100644 --- a/sqlx-mysql/src/lib.rs +++ b/sqlx-mysql/src/lib.rs @@ -17,6 +17,8 @@ #![warn(clippy::use_self)] #![warn(clippy::useless_let_if_seq)] #![allow(clippy::doc_markdown)] +#![allow(clippy::missing_errors_doc)] +#![allow(clippy::missing_panics_doc)] #[macro_use] mod stream; @@ -31,11 +33,11 @@ mod output; mod protocol; mod query_result; mod raw_statement; +mod raw_value; mod row; mod type_id; mod type_info; pub mod types; -mod raw_value; #[cfg(test)] mod mock; @@ -47,7 +49,7 @@ pub use error::MySqlDatabaseError; pub use options::MySqlConnectOptions; pub use output::MySqlOutput; pub use query_result::MySqlQueryResult; +pub use raw_value::{MySqlRawValue, MySqlRawValueFormat}; pub use row::MySqlRow; pub use type_id::MySqlTypeId; pub use type_info::MySqlTypeInfo; -pub use raw_value::{MySqlRawValue, MySqlRawValueFormat}; diff --git a/sqlx-mysql/src/output.rs b/sqlx-mysql/src/output.rs index 4219ce8f..65f7f464 100644 --- a/sqlx-mysql/src/output.rs +++ b/sqlx-mysql/src/output.rs @@ -3,6 +3,7 @@ use crate::MySqlTypeId; // 'x: single execution +#[allow(clippy::module_name_repetitions)] pub struct MySqlOutput<'x> { buffer: &'x mut Vec, null_offset: usize, diff --git a/sqlx-mysql/src/protocol/execute.rs b/sqlx-mysql/src/protocol/execute.rs index 552e48f6..2eb3ca8f 100644 --- a/sqlx-mysql/src/protocol/execute.rs +++ b/sqlx-mysql/src/protocol/execute.rs @@ -43,18 +43,14 @@ impl Serialize<'_> for Execute<'_, '_> { let mut args = self.arguments.positional(); for param in self.parameters { - match args.next() { - Some(argument) => { - argument.encode(param, &mut out)?; - out.declare(argument.type_id(param)); - } - - None => { - // if we run out of values, start sending NULL for - // each subsequent parameter - out.null(); - out.declare(MySqlTypeId::NULL); - } + if let Some(argument) = args.next() { + argument.encode(param, &mut out)?; + out.declare(argument.type_id(param)); + } else { + // if we run out of values, start sending NULL for + // each subsequent parameter + out.null(); + out.declare(MySqlTypeId::NULL); } } diff --git a/sqlx-mysql/src/raw_value.rs b/sqlx-mysql/src/raw_value.rs index 84c62f4a..141507c7 100644 --- a/sqlx-mysql/src/raw_value.rs +++ b/sqlx-mysql/src/raw_value.rs @@ -19,6 +19,7 @@ pub enum MySqlRawValueFormat { /// The raw representation of a SQL value for MySQL. #[derive(Debug, Clone)] +#[allow(clippy::module_name_repetitions)] pub struct MySqlRawValue<'r> { value: Option<&'r Bytes>, format: MySqlRawValueFormat, @@ -27,7 +28,7 @@ pub struct MySqlRawValue<'r> { // 'r: row impl<'r> MySqlRawValue<'r> { - pub(crate) fn new( + pub(crate) const fn new( value: &'r Option, format: MySqlRawValueFormat, type_info: &'r MySqlTypeInfo, diff --git a/sqlx-mysql/src/type_id.rs b/sqlx-mysql/src/type_id.rs index 4b3b18d9..847f000e 100644 --- a/sqlx-mysql/src/type_id.rs +++ b/sqlx-mysql/src/type_id.rs @@ -6,6 +6,7 @@ use crate::protocol::{ColumnDefinition, ColumnFlags}; any(feature = "offline", feature = "serde"), derive(serde::Serialize, serde::Deserialize) )] +#[allow(clippy::module_name_repetitions)] pub struct MySqlTypeId(u8, u8); // a flag byte which has the highest bit set to indicate the type is unsigned @@ -39,16 +40,16 @@ impl MySqlTypeId { pub(crate) const fn is_integer(&self) -> bool { matches!( *self, - MySqlTypeId::TINYINT - | MySqlTypeId::TINYINT_UNSIGNED - | MySqlTypeId::SMALLINT - | MySqlTypeId::SMALLINT_UNSIGNED - | MySqlTypeId::MEDIUMINT - | MySqlTypeId::MEDIUMINT_UNSIGNED - | MySqlTypeId::INT - | MySqlTypeId::INT_UNSIGNED - | MySqlTypeId::BIGINT - | MySqlTypeId::BIGINT_UNSIGNED + Self::TINYINT + | Self::TINYINT_UNSIGNED + | Self::SMALLINT + | Self::SMALLINT_UNSIGNED + | Self::MEDIUMINT + | Self::MEDIUMINT_UNSIGNED + | Self::INT + | Self::INT_UNSIGNED + | Self::BIGINT + | Self::BIGINT_UNSIGNED ) } @@ -93,7 +94,7 @@ impl MySqlTypeId { /// If the display width is 1 ( `TINYINT(1)` ), maps to `bool`. Otherwise, /// maps to `i8`. /// - pub const TINYINT: MySqlTypeId = MySqlTypeId(1, 0); + pub const TINYINT: Self = Self(1, 0); /// An unsigned 8-bit integer. /// @@ -102,7 +103,7 @@ impl MySqlTypeId { /// If the display width is 1 ( `TINYINT(1) UNSIGNED` ), maps to `bool`. Otherwise, /// maps to `u8`. /// - pub const TINYINT_UNSIGNED: MySqlTypeId = MySqlTypeId(1, UNSIGNED); + pub const TINYINT_UNSIGNED: Self = Self(1, UNSIGNED); /// A 16-bit integer. /// @@ -110,7 +111,7 @@ impl MySqlTypeId { /// /// Maps to `i16`. /// - pub const SMALLINT: MySqlTypeId = MySqlTypeId(2, 0); + pub const SMALLINT: Self = Self(2, 0); /// An unsigned 16-bit integer. /// @@ -118,7 +119,7 @@ impl MySqlTypeId { /// /// Maps to `u16`. /// - pub const SMALLINT_UNSIGNED: MySqlTypeId = MySqlTypeId(2, UNSIGNED); + pub const SMALLINT_UNSIGNED: Self = Self(2, UNSIGNED); /// A 24-bit integer. /// @@ -126,7 +127,7 @@ impl MySqlTypeId { /// /// Maps to `i32`. /// - pub const MEDIUMINT: MySqlTypeId = MySqlTypeId(9, 0); + pub const MEDIUMINT: Self = Self(9, 0); /// An unsigned 24-bit integer. /// @@ -134,7 +135,7 @@ impl MySqlTypeId { /// /// Maps to `u32`. /// - pub const MEDIUMINT_UNSIGNED: MySqlTypeId = MySqlTypeId(9, UNSIGNED); + pub const MEDIUMINT_UNSIGNED: Self = Self(9, UNSIGNED); /// A 32-bit integer. /// @@ -142,7 +143,7 @@ impl MySqlTypeId { /// /// Maps to `i32`. /// - pub const INT: MySqlTypeId = MySqlTypeId(3, 0); + pub const INT: Self = Self(3, 0); /// An unsigned 32-bit integer. /// @@ -150,7 +151,7 @@ impl MySqlTypeId { /// /// Maps to `u32`. /// - pub const INT_UNSIGNED: MySqlTypeId = MySqlTypeId(3, UNSIGNED); + pub const INT_UNSIGNED: Self = Self(3, UNSIGNED); /// A 64-bit integer. /// @@ -158,7 +159,7 @@ impl MySqlTypeId { /// /// Maps to `i64`. /// - pub const BIGINT: MySqlTypeId = MySqlTypeId(8, 0); + pub const BIGINT: Self = Self(8, 0); /// An unsigned 64-bit integer. /// @@ -166,7 +167,7 @@ impl MySqlTypeId { /// /// Maps to `u64`. /// - pub const BIGINT_UNSIGNED: MySqlTypeId = MySqlTypeId(8, UNSIGNED); + pub const BIGINT_UNSIGNED: Self = Self(8, UNSIGNED); /// A 4-byte approximate numeric data value. /// @@ -174,7 +175,7 @@ impl MySqlTypeId { /// /// Maps to `f32`. /// - pub const FLOAT: MySqlTypeId = MySqlTypeId(4, 0); + pub const FLOAT: Self = Self(4, 0); /// An 8-byte approximate numeric data value. /// @@ -182,7 +183,7 @@ impl MySqlTypeId { /// /// Maps to `f64`. /// - pub const DOUBLE: MySqlTypeId = MySqlTypeId(5, 0); + pub const DOUBLE: Self = Self(5, 0); /// Always `NULL`. /// @@ -197,5 +198,5 @@ impl MySqlTypeId { /// is a dynamic or type-erased `NULL`. Unlike `Option<_>::None`, [`Null`] can be /// used to send a SQL `NULL` without knowing the SQL type. /// - pub const NULL: MySqlTypeId = MySqlTypeId(6, 0); + pub const NULL: Self = Self(6, 0); } diff --git a/sqlx-mysql/src/type_info.rs b/sqlx-mysql/src/type_info.rs index fba4bf89..a02cbff2 100644 --- a/sqlx-mysql/src/type_info.rs +++ b/sqlx-mysql/src/type_info.rs @@ -9,6 +9,7 @@ use crate::{MySql, MySqlTypeId}; any(feature = "offline", feature = "serde"), derive(serde::Serialize, serde::Deserialize) )] +#[allow(clippy::module_name_repetitions)] pub struct MySqlTypeInfo { id: MySqlTypeId, charset: u16, diff --git a/sqlx-mysql/src/types/uint.rs b/sqlx-mysql/src/types/uint.rs index d067eefe..26fa224e 100644 --- a/sqlx-mysql/src/types/uint.rs +++ b/sqlx-mysql/src/types/uint.rs @@ -15,7 +15,7 @@ use crate::{MySql, MySqlOutput, MySqlRawValue, MySqlRawValueFormat, MySqlTypeId} const NUMBER_TOO_LARGE: &str = "number too large to fit in target type"; // shared among all Decode impls for unsigned and signed integers -fn decode_int_or_uint(value: MySqlRawValue<'_>) -> decode::Result +fn decode_int_or_uint(value: &MySqlRawValue<'_>) -> decode::Result where T: TryFrom + TryFrom + FromStr, >::Error: 'static + StdError + Send + Sync, @@ -72,6 +72,6 @@ impl Encode for u8 { impl<'r> Decode<'r, MySql> for u8 { fn decode(value: MySqlRawValue<'r>) -> decode::Result { - decode_int_or_uint(value) + decode_int_or_uint(&value) } }