Skip to content

Commit

Permalink
fix newly introduced clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
conradludgate committed Jan 29, 2025
1 parent a7dac54 commit 8b44892
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion postgres-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ macro_rules! from_usize {
impl FromUsize for $t {
#[inline]
fn from_usize(x: usize) -> io::Result<$t> {
if x > <$t>::max_value() as usize {
if x > <$t>::MAX as usize {
Err(io::Error::new(
io::ErrorKind::InvalidInput,
"value too large to transmit",
Expand Down
8 changes: 4 additions & 4 deletions postgres-protocol/src/message/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ pub struct ColumnFormats<'a> {
remaining: u16,
}

impl<'a> FallibleIterator for ColumnFormats<'a> {
impl FallibleIterator for ColumnFormats<'_> {
type Item = u16;
type Error = io::Error;

Expand Down Expand Up @@ -694,7 +694,7 @@ pub struct DataRowRanges<'a> {
remaining: u16,
}

impl<'a> FallibleIterator for DataRowRanges<'a> {
impl FallibleIterator for DataRowRanges<'_> {
type Item = Option<Range<usize>>;
type Error = io::Error;

Expand Down Expand Up @@ -782,7 +782,7 @@ pub struct ErrorField<'a> {
value: &'a str,
}

impl<'a> ErrorField<'a> {
impl ErrorField<'_> {
#[inline]
pub fn type_(&self) -> u8 {
self.type_
Expand Down Expand Up @@ -848,7 +848,7 @@ pub struct Parameters<'a> {
remaining: u16,
}

impl<'a> FallibleIterator for Parameters<'a> {
impl FallibleIterator for Parameters<'_> {
type Item = Oid;
type Error = io::Error;

Expand Down
4 changes: 2 additions & 2 deletions postgres-protocol/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ impl<'a> Array<'a> {
/// An iterator over the dimensions of an array.
pub struct ArrayDimensions<'a>(&'a [u8]);

impl<'a> FallibleIterator for ArrayDimensions<'a> {
impl FallibleIterator for ArrayDimensions<'_> {
type Item = ArrayDimension;
type Error = StdBox<dyn Error + Sync + Send>;

Expand Down Expand Up @@ -950,7 +950,7 @@ pub struct PathPoints<'a> {
buf: &'a [u8],
}

impl<'a> FallibleIterator for PathPoints<'a> {
impl FallibleIterator for PathPoints<'_> {
type Item = Point;
type Error = StdBox<dyn Error + Sync + Send>;

Expand Down
12 changes: 6 additions & 6 deletions postgres-protocol/src/types/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ fn ltree_str() {
let mut query = vec![1u8];
query.extend_from_slice("A.B.C".as_bytes());

assert!(matches!(ltree_from_sql(query.as_slice()), Ok(_)))
assert!(ltree_from_sql(query.as_slice()).is_ok())
}

#[test]
fn ltree_wrong_version() {
let mut query = vec![2u8];
query.extend_from_slice("A.B.C".as_bytes());

assert!(matches!(ltree_from_sql(query.as_slice()), Err(_)))
assert!(ltree_from_sql(query.as_slice()).is_err())
}

#[test]
Expand All @@ -202,15 +202,15 @@ fn lquery_str() {
let mut query = vec![1u8];
query.extend_from_slice("A.B.C".as_bytes());

assert!(matches!(lquery_from_sql(query.as_slice()), Ok(_)))
assert!(lquery_from_sql(query.as_slice()).is_ok())
}

#[test]
fn lquery_wrong_version() {
let mut query = vec![2u8];
query.extend_from_slice("A.B.C".as_bytes());

assert!(matches!(lquery_from_sql(query.as_slice()), Err(_)))
assert!(lquery_from_sql(query.as_slice()).is_err())
}

#[test]
Expand All @@ -230,13 +230,13 @@ fn ltxtquery_str() {
let mut query = vec![1u8];
query.extend_from_slice("a & b*".as_bytes());

assert!(matches!(ltree_from_sql(query.as_slice()), Ok(_)))
assert!(ltree_from_sql(query.as_slice()).is_ok())
}

#[test]
fn ltxtquery_wrong_version() {
let mut query = vec![2u8];
query.extend_from_slice("a & b*".as_bytes());

assert!(matches!(ltree_from_sql(query.as_slice()), Err(_)))
assert!(ltree_from_sql(query.as_slice()).is_err())
}
1 change: 1 addition & 0 deletions postgres-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ keywords = ["database", "postgres", "postgresql", "sql"]
categories = ["database"]

[features]
default = ["with-chrono-0_4"]
derive = ["postgres-derive"]
array-impls = ["array-init"]
with-bit-vec-0_6 = ["bit-vec-06"]
Expand Down
14 changes: 7 additions & 7 deletions postgres-types/src/chrono_04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn base() -> NaiveDateTime {
.unwrap()
}

impl<'a> FromSql<'a> for NaiveDateTime {
impl FromSql<'_> for NaiveDateTime {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveDateTime, Box<dyn Error + Sync + Send>> {
let t = types::timestamp_from_sql(raw)?;
base()
Expand All @@ -39,7 +39,7 @@ impl ToSql for NaiveDateTime {
to_sql_checked!();
}

impl<'a> FromSql<'a> for DateTime<Utc> {
impl FromSql<'_> for DateTime<Utc> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Utc>, Box<dyn Error + Sync + Send>> {
let naive = NaiveDateTime::from_sql(type_, raw)?;
Ok(Utc.from_utc_datetime(&naive))
Expand All @@ -61,7 +61,7 @@ impl ToSql for DateTime<Utc> {
to_sql_checked!();
}

impl<'a> FromSql<'a> for DateTime<Local> {
impl FromSql<'_> for DateTime<Local> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Local>, Box<dyn Error + Sync + Send>> {
let utc = DateTime::<Utc>::from_sql(type_, raw)?;
Ok(utc.with_timezone(&Local))
Expand All @@ -83,7 +83,7 @@ impl ToSql for DateTime<Local> {
to_sql_checked!();
}

impl<'a> FromSql<'a> for DateTime<FixedOffset> {
impl FromSql<'_> for DateTime<FixedOffset> {
fn from_sql(
type_: &Type,
raw: &[u8],
Expand All @@ -108,7 +108,7 @@ impl ToSql for DateTime<FixedOffset> {
to_sql_checked!();
}

impl<'a> FromSql<'a> for NaiveDate {
impl FromSql<'_> for NaiveDate {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveDate, Box<dyn Error + Sync + Send>> {
let jd = types::date_from_sql(raw)?;
base()
Expand All @@ -123,7 +123,7 @@ impl<'a> FromSql<'a> for NaiveDate {
impl ToSql for NaiveDate {
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
let jd = self.signed_duration_since(base().date()).num_days();
if jd > i64::from(i32::max_value()) || jd < i64::from(i32::min_value()) {
if jd > i64::from(i32::MAX) || jd < i64::from(i32::MIN) {
return Err("value too large to transmit".into());
}

Expand All @@ -135,7 +135,7 @@ impl ToSql for NaiveDate {
to_sql_checked!();
}

impl<'a> FromSql<'a> for NaiveTime {
impl FromSql<'_> for NaiveTime {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveTime, Box<dyn Error + Sync + Send>> {
let usec = types::time_from_sql(raw)?;
Ok(NaiveTime::from_hms_opt(0, 0, 0).unwrap() + Duration::microseconds(usec))
Expand Down
22 changes: 11 additions & 11 deletions postgres-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ pub enum Format {
Binary,
}

impl<'a, T> ToSql for &'a T
impl<T> ToSql for &T
where
T: ToSql,
{
Expand Down Expand Up @@ -950,7 +950,7 @@ impl<T: ToSql> ToSql for Option<T> {
to_sql_checked!();
}

impl<'a, T: ToSql> ToSql for &'a [T] {
impl<T: ToSql> ToSql for &[T] {
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
let member_type = match *ty.kind() {
Kind::Array(ref member) => member,
Expand Down Expand Up @@ -991,7 +991,7 @@ impl<'a, T: ToSql> ToSql for &'a [T] {
to_sql_checked!();
}

impl<'a> ToSql for &'a [u8] {
impl ToSql for &[u8] {
fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
types::bytea_to_sql(self, w);
Ok(IsNull::No)
Expand Down Expand Up @@ -1051,7 +1051,7 @@ impl<T: ToSql> ToSql for Box<[T]> {
to_sql_checked!();
}

impl<'a> ToSql for Cow<'a, [u8]> {
impl ToSql for Cow<'_, [u8]> {
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
<&[u8] as ToSql>::to_sql(&self.as_ref(), ty, w)
}
Expand All @@ -1075,7 +1075,7 @@ impl ToSql for Vec<u8> {
to_sql_checked!();
}

impl<'a> ToSql for &'a str {
impl ToSql for &str {
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
match ty.name() {
"ltree" => types::ltree_to_sql(self, w),
Expand All @@ -1096,7 +1096,7 @@ impl<'a> ToSql for &'a str {
to_sql_checked!();
}

impl<'a> ToSql for Cow<'a, str> {
impl ToSql for Cow<'_, str> {
fn to_sql(&self, ty: &Type, w: &mut BytesMut) -> Result<IsNull, Box<dyn Error + Sync + Send>> {
<&str as ToSql>::to_sql(&self.as_ref(), ty, w)
}
Expand Down Expand Up @@ -1215,7 +1215,7 @@ impl ToSql for IpAddr {
}

fn downcast(len: usize) -> Result<i32, Box<dyn Error + Sync + Send>> {
if len > i32::max_value() as usize {
if len > i32::MAX as usize {
Err("value too large to transmit".into())
} else {
Ok(len as i32)
Expand Down Expand Up @@ -1243,17 +1243,17 @@ impl BorrowToSql for &dyn ToSql {
}
}

impl<'a> sealed::Sealed for Box<dyn ToSql + Sync + 'a> {}
impl sealed::Sealed for Box<dyn ToSql + Sync + '_> {}

impl<'a> BorrowToSql for Box<dyn ToSql + Sync + 'a> {
impl BorrowToSql for Box<dyn ToSql + Sync + '_> {
#[inline]
fn borrow_to_sql(&self) -> &dyn ToSql {
self.as_ref()
}
}

impl<'a> sealed::Sealed for Box<dyn ToSql + Sync + Send + 'a> {}
impl<'a> BorrowToSql for Box<dyn ToSql + Sync + Send + 'a> {
impl sealed::Sealed for Box<dyn ToSql + Sync + Send + '_> {}
impl BorrowToSql for Box<dyn ToSql + Sync + Send + '_> {
#[inline]
fn borrow_to_sql(&self) -> &dyn ToSql {
self.as_ref()
Expand Down
1 change: 0 additions & 1 deletion postgres-types/src/special.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use bytes::BytesMut;
use postgres_protocol::types;
use std::error::Error;
use std::{i32, i64};

use crate::{FromSql, IsNull, ToSql, Type};

Expand Down
6 changes: 3 additions & 3 deletions postgres/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct Iter<'a> {
connection: ConnectionRef<'a>,
}

impl<'a> FallibleIterator for Iter<'a> {
impl FallibleIterator for Iter<'_> {
type Item = Notification;
type Error = Error;

Expand All @@ -100,7 +100,7 @@ pub struct BlockingIter<'a> {
connection: ConnectionRef<'a>,
}

impl<'a> FallibleIterator for BlockingIter<'a> {
impl FallibleIterator for BlockingIter<'_> {
type Item = Notification;
type Error = Error;

Expand Down Expand Up @@ -129,7 +129,7 @@ pub struct TimeoutIter<'a> {
timeout: Duration,
}

impl<'a> FallibleIterator for TimeoutIter<'a> {
impl FallibleIterator for TimeoutIter<'_> {
type Item = Notification;
type Error = Error;

Expand Down
2 changes: 1 addition & 1 deletion postgres/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Transaction<'a> {
transaction: Option<tokio_postgres::Transaction<'a>>,
}

impl<'a> Drop for Transaction<'a> {
impl Drop for Transaction<'_> {
fn drop(&mut self) {
if let Some(transaction) = self.transaction.take() {
let _ = self.connection.block_on(transaction.rollback());
Expand Down
2 changes: 1 addition & 1 deletion tokio-postgres/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl Client {
done: bool,
}

impl<'a> Drop for RollbackIfNotDone<'a> {
impl Drop for RollbackIfNotDone<'_> {
fn drop(&mut self) {
if self.done {
return;
Expand Down
2 changes: 1 addition & 1 deletion tokio-postgres/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::task::{Context, Poll};

struct BorrowToSqlParamsDebug<'a, T>(&'a [T]);

impl<'a, T> fmt::Debug for BorrowToSqlParamsDebug<'a, T>
impl<T> fmt::Debug for BorrowToSqlParamsDebug<'_, T>
where
T: BorrowToSql,
{
Expand Down
4 changes: 2 additions & 2 deletions tokio-postgres/src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ impl RowIndex for str {
}
}

impl<'a, T> Sealed for &'a T where T: ?Sized + Sealed {}
impl<T> Sealed for &T where T: ?Sized + Sealed {}

impl<'a, T> RowIndex for &'a T
impl<T> RowIndex for &T
where
T: ?Sized + RowIndex,
{
Expand Down
2 changes: 1 addition & 1 deletion tokio-postgres/src/to_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod private {
Query(&'a str),
}

impl<'a> ToStatementType<'a> {
impl ToStatementType<'_> {
pub async fn into_statement(self, client: &Client) -> Result<Statement, Error> {
match self {
ToStatementType::Statement(s) => Ok(s.clone()),
Expand Down
2 changes: 1 addition & 1 deletion tokio-postgres/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Savepoint {
depth: u32,
}

impl<'a> Drop for Transaction<'a> {
impl Drop for Transaction<'_> {
fn drop(&mut self) {
if self.done {
return;
Expand Down
4 changes: 2 additions & 2 deletions tokio-postgres/tests/test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async fn simple_query() {
}
match &messages[2] {
SimpleQueryMessage::Row(row) => {
assert_eq!(row.columns().get(0).map(|c| c.name()), Some("id"));
assert_eq!(row.columns().first().map(|c| c.name()), Some("id"));
assert_eq!(row.columns().get(1).map(|c| c.name()), Some("name"));
assert_eq!(row.get(0), Some("1"));
assert_eq!(row.get(1), Some("steven"));
Expand All @@ -339,7 +339,7 @@ async fn simple_query() {
}
match &messages[3] {
SimpleQueryMessage::Row(row) => {
assert_eq!(row.columns().get(0).map(|c| c.name()), Some("id"));
assert_eq!(row.columns().first().map(|c| c.name()), Some("id"));
assert_eq!(row.columns().get(1).map(|c| c.name()), Some("name"));
assert_eq!(row.get(0), Some("2"));
assert_eq!(row.get(1), Some("joe"));
Expand Down
2 changes: 1 addition & 1 deletion tokio-postgres/tests/test/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ async fn domain() {
to_sql_checked!();
}

impl<'a> FromSql<'a> for SessionId {
impl FromSql<'_> for SessionId {
fn from_sql(ty: &Type, raw: &[u8]) -> result::Result<Self, Box<dyn Error + Sync + Send>> {
Vec::<u8>::from_sql(ty, raw).map(SessionId)
}
Expand Down

0 comments on commit 8b44892

Please sign in to comment.