Skip to content

Fix clippy lint warnings regarding indirect structural matches #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions postgres-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@
//! }
//! ```
#![doc(html_root_url = "https://docs.rs/postgres-types/0.1")]
#![warn(clippy::all, rust_2018_idioms, missing_docs)]
#![warn(clippy::all, future_incompatible, rust_2018_idioms, missing_docs)]

use fallible_iterator::FallibleIterator;
use postgres_protocol::types::{self, ArrayDimension};
@@ -144,8 +144,8 @@ const NSEC_PER_USEC: u64 = 1_000;
macro_rules! accepts {
($($expected:ident),+) => (
fn accepts(ty: &$crate::Type) -> bool {
match *ty {
$($crate::Type::$expected)|+ => true,
match ty {
$(typ if *typ == $crate::Type::$expected => true,)*
_ => false
}
}
@@ -536,8 +536,15 @@ impl<'a> FromSql<'a> for &'a str {
}

fn accepts(ty: &Type) -> bool {
match *ty {
Type::VARCHAR | Type::TEXT | Type::BPCHAR | Type::NAME | Type::UNKNOWN => true,
match ty {
typ if *typ == Type::VARCHAR
|| *typ == Type::TEXT
|| *typ == Type::BPCHAR
|| *typ == Type::NAME
|| *typ == Type::UNKNOWN =>
{
true
}
ref ty if ty.name() == "citext" => true,
_ => false,
}
@@ -830,8 +837,15 @@ impl<'a> ToSql for &'a str {
}

fn accepts(ty: &Type) -> bool {
match *ty {
Type::VARCHAR | Type::TEXT | Type::BPCHAR | Type::NAME | Type::UNKNOWN => true,
match ty {
typ if *typ == Type::VARCHAR
|| *typ == Type::TEXT
|| *typ == Type::BPCHAR
|| *typ == Type::NAME
|| *typ == Type::UNKNOWN =>
{
true
}
ref ty if ty.name() == "citext" => true,
_ => false,
}
12 changes: 8 additions & 4 deletions postgres-types/src/special.rs
Original file line number Diff line number Diff line change
@@ -75,8 +75,10 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Timestamp<T> {
}

fn accepts(ty: &Type) -> bool {
match *ty {
Type::TIMESTAMP | Type::TIMESTAMPTZ if T::accepts(ty) => true,
match ty {
typ if (*typ == Type::TIMESTAMP || *typ == Type::TIMESTAMPTZ) && T::accepts(&ty) => {
true
}
_ => false,
}
}
@@ -99,8 +101,10 @@ impl<T: ToSql> ToSql for Timestamp<T> {
}

fn accepts(ty: &Type) -> bool {
match *ty {
Type::TIMESTAMP | Type::TIMESTAMPTZ if T::accepts(ty) => true,
match ty {
typ if (*typ == Type::TIMESTAMP || *typ == Type::TIMESTAMPTZ) && T::accepts(&ty) => {
true
}
_ => false,
}
}