diff --git a/codegen/src/sqlstate.rs b/codegen/src/sqlstate.rs index d21b92eec..9b9be6c54 100644 --- a/codegen/src/sqlstate.rs +++ b/codegen/src/sqlstate.rs @@ -72,7 +72,6 @@ fn make_code(codes: &LinkedHashMap>, file: &mut BufWriter "{code}","#, - code = code, ) .unwrap(); } @@ -97,8 +96,6 @@ fn make_consts(codes: &LinkedHashMap>, file: &mut BufWriter< /// {code} pub const {name}: SqlState = SqlState(Inner::E{code}); "#, - name = name, - code = code, ) .unwrap(); } @@ -121,8 +118,7 @@ enum Inner {{"#, write!( file, r#" - E{},"#, - code, + E{code},"#, ) .unwrap(); } diff --git a/codegen/src/type_gen.rs b/codegen/src/type_gen.rs index fd7a56450..1b80a5101 100644 --- a/codegen/src/type_gen.rs +++ b/codegen/src/type_gen.rs @@ -237,7 +237,7 @@ fn parse_types() -> BTreeMap { let doc_name = array_re.replace(&name, "$1[]").to_ascii_uppercase(); let mut doc = doc_name.clone(); if let Some(descr) = raw_type.get("descr") { - write!(doc, " - {}", descr).unwrap(); + write!(doc, " - {descr}").unwrap(); } let doc = Escape::new(doc.as_bytes().iter().cloned()).collect(); let doc = String::from_utf8(doc).unwrap(); @@ -245,10 +245,10 @@ fn parse_types() -> BTreeMap { if let Some(array_type_oid) = raw_type.get("array_type_oid") { let array_type_oid = array_type_oid.parse::().unwrap(); - let name = format!("_{}", name); - let variant = format!("{}Array", variant); - let doc = format!("{}[]", doc_name); - let ident = format!("{}_ARRAY", ident); + let name = format!("_{name}"); + let variant = format!("{variant}Array"); + let doc = format!("{doc_name}[]"); + let ident = format!("{ident}_ARRAY"); let type_ = Type { name, diff --git a/postgres-derive-test/src/lib.rs b/postgres-derive-test/src/lib.rs index f0534f32c..5c0b63413 100644 --- a/postgres-derive-test/src/lib.rs +++ b/postgres-derive-test/src/lib.rs @@ -21,7 +21,7 @@ where let result = conn.query_one(&stmt, &[]).unwrap().get(0); assert_eq!(val, &result); - let stmt = conn.prepare(&format!("SELECT $1::{}", sql_type)).unwrap(); + let stmt = conn.prepare(&format!("SELECT $1::{sql_type}")).unwrap(); let result = conn.query_one(&stmt, &[val]).unwrap().get(0); assert_eq!(val, &result); } @@ -45,7 +45,7 @@ pub fn test_type_asymmetric( let result: F = conn.query_one(&stmt, &[]).unwrap().get(0); assert!(cmp(val, &result)); - let stmt = conn.prepare(&format!("SELECT $1::{}", sql_type)).unwrap(); + let stmt = conn.prepare(&format!("SELECT $1::{sql_type}")).unwrap(); let result: F = conn.query_one(&stmt, &[val]).unwrap().get(0); assert!(cmp(val, &result)); } diff --git a/postgres-derive/src/overrides.rs b/postgres-derive/src/overrides.rs index d50550bee..712d13aac 100644 --- a/postgres-derive/src/overrides.rs +++ b/postgres-derive/src/overrides.rs @@ -65,7 +65,7 @@ impl Overrides { "invalid rename_all rule, expected one of: {}", RENAME_RULES .iter() - .map(|rule| format!("\"{}\"", rule)) + .map(|rule| format!("\"{rule}\"")) .collect::>() .join(", ") ), diff --git a/postgres-derive/src/tosql.rs b/postgres-derive/src/tosql.rs index 81d4834bf..e16117aa3 100644 --- a/postgres-derive/src/tosql.rs +++ b/postgres-derive/src/tosql.rs @@ -196,7 +196,7 @@ fn composite_body(fields: &[Field]) -> TokenStream { postgres_types::IsNull::Yes => -1, postgres_types::IsNull::No => { let len = buf.len() - base - 4; - if len > i32::max_value() as usize { + if len > i32::MAX as usize { return std::result::Result::Err( std::convert::Into::into("value too large to transmit")); } diff --git a/postgres-protocol/src/authentication/mod.rs b/postgres-protocol/src/authentication/mod.rs index 71afa4b9b..efe7ce778 100644 --- a/postgres-protocol/src/authentication/mod.rs +++ b/postgres-protocol/src/authentication/mod.rs @@ -14,7 +14,7 @@ pub fn md5_hash(username: &[u8], password: &[u8], salt: [u8; 4]) -> String { md5.update(password); md5.update(username); let output = md5.finalize_reset(); - md5.update(format!("{:x}", output)); + md5.update(format!("{output:x}")); md5.update(salt); format!("md5{:x}", md5.finalize()) } diff --git a/postgres-protocol/src/authentication/sasl.rs b/postgres-protocol/src/authentication/sasl.rs index 85a589c99..d391e897c 100644 --- a/postgres-protocol/src/authentication/sasl.rs +++ b/postgres-protocol/src/authentication/sasl.rs @@ -262,7 +262,7 @@ impl ScramSha256 { let verifier = match parsed { ServerFinalMessage::Error(e) => { - return Err(io::Error::other(format!("SCRAM error: {}", e))); + return Err(io::Error::other(format!("SCRAM error: {e}"))); } ServerFinalMessage::Verifier(verifier) => verifier, }; @@ -302,10 +302,8 @@ impl<'a> Parser<'a> { match self.it.next() { Some((_, c)) if c == target => Ok(()), Some((i, c)) => { - let m = format!( - "unexpected character at byte {}: expected `{}` but got `{}", - i, target, c - ); + let m = + format!("unexpected character at byte {i}: expected `{target}` but got `{c}"); Err(io::Error::new(io::ErrorKind::InvalidInput, m)) } None => Err(io::Error::new( @@ -371,7 +369,7 @@ impl<'a> Parser<'a> { match self.it.peek() { Some(&(i, _)) => Err(io::Error::new( io::ErrorKind::InvalidInput, - format!("unexpected trailing data at byte {}", i), + format!("unexpected trailing data at byte {i}"), )), None => Ok(()), } diff --git a/postgres-protocol/src/message/backend.rs b/postgres-protocol/src/message/backend.rs index 013bfbb81..f64de84d9 100644 --- a/postgres-protocol/src/message/backend.rs +++ b/postgres-protocol/src/message/backend.rs @@ -235,7 +235,7 @@ impl Message { tag => { return Err(io::Error::new( io::ErrorKind::InvalidInput, - format!("unknown authentication tag `{}`", tag), + format!("unknown authentication tag `{tag}`"), )); } }, @@ -262,7 +262,7 @@ impl Message { tag => { return Err(io::Error::new( io::ErrorKind::InvalidInput, - format!("unknown message tag `{}`", tag), + format!("unknown message tag `{tag}`"), )); } }; diff --git a/postgres-protocol/src/password/mod.rs b/postgres-protocol/src/password/mod.rs index 445fb0c0e..de070cf21 100644 --- a/postgres-protocol/src/password/mod.rs +++ b/postgres-protocol/src/password/mod.rs @@ -102,5 +102,5 @@ pub fn md5(password: &[u8], username: &str) -> String { let mut hash = Md5::new(); hash.update(&salted_password); let digest = hash.finalize(); - format!("md5{:x}", digest) + format!("md5{digest:x}") } diff --git a/postgres-types/src/chrono_04.rs b/postgres-types/src/chrono_04.rs index d599bde02..007ddb04c 100644 --- a/postgres-types/src/chrono_04.rs +++ b/postgres-types/src/chrono_04.rs @@ -3,7 +3,7 @@ use chrono_04::{ DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc, }; use postgres_protocol::types; -use std::error::Error; +use std::{convert::TryFrom, error::Error}; use crate::{FromSql, IsNull, ToSql, Type}; @@ -123,11 +123,9 @@ impl<'a> FromSql<'a> for NaiveDate { impl ToSql for NaiveDate { fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result> { let jd = self.signed_duration_since(base().date()).num_days(); - if jd > i64::from(i32::max_value()) || jd < i64::from(i32::min_value()) { - return Err("value too large to transmit".into()); - } + let jd = i32::try_from(jd).map_err(|_| "value too large to transmit")?; - types::date_to_sql(jd as i32, w); + types::date_to_sql(jd, w); Ok(IsNull::No) } diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index 51137b6b4..6aba69501 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -319,7 +319,7 @@ impl fmt::Display for Type { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self.schema() { "public" | "pg_catalog" => {} - schema => write!(fmt, "{}.", schema)?, + schema => write!(fmt, "{schema}.")?, } fmt.write_str(self.name()) } @@ -631,16 +631,14 @@ impl<'a, T: FromSql<'a>, const N: usize> FromSql<'a> for [T; N] { let v = values .next()? .ok_or_else(|| -> Box { - format!("too few elements in array (expected {}, got {})", N, i).into() + format!("too few elements in array (expected {N}, got {i})").into() })?; T::from_sql_nullable(member_type, v) })?; if values.next()?.is_some() { - return Err(format!( - "excess elements in array (expected {}, got more than that)", - N, - ) - .into()); + return Err( + format!("excess elements in array (expected {N}, got more than that)",).into(), + ); } Ok(out) diff --git a/postgres-types/src/pg_lsn.rs b/postgres-types/src/pg_lsn.rs index f339f9689..51004b329 100644 --- a/postgres-types/src/pg_lsn.rs +++ b/postgres-types/src/pg_lsn.rs @@ -52,7 +52,7 @@ impl fmt::Display for PgLsn { impl fmt::Debug for PgLsn { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_fmt(format_args!("{}", self)) + fmt::Display::fmt(self, f) } } diff --git a/postgres-types/src/time_02.rs b/postgres-types/src/time_02.rs index 19a8909e7..47c98757d 100644 --- a/postgres-types/src/time_02.rs +++ b/postgres-types/src/time_02.rs @@ -72,11 +72,9 @@ impl<'a> FromSql<'a> for Date { impl ToSql for Date { fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result> { let jd = (*self - base().date()).whole_days(); - if jd > i64::from(i32::max_value()) || jd < i64::from(i32::min_value()) { - return Err("value too large to transmit".into()); - } + let jd = i32::try_from(jd).map_err(|_| "value too large to transmit")?; - types::date_to_sql(jd as i32, w); + types::date_to_sql(jd, w); Ok(IsNull::No) } diff --git a/postgres-types/src/time_03.rs b/postgres-types/src/time_03.rs index 4deea663f..2c2904d11 100644 --- a/postgres-types/src/time_03.rs +++ b/postgres-types/src/time_03.rs @@ -76,11 +76,9 @@ impl<'a> FromSql<'a> for Date { impl ToSql for Date { fn to_sql(&self, _: &Type, w: &mut BytesMut) -> Result> { let jd = (*self - base().date()).whole_days(); - if jd > i64::from(i32::max_value()) || jd < i64::from(i32::min_value()) { - return Err("value too large to transmit".into()); - } + let jd = i32::try_from(jd).map_err(|_| "value too large to transmit")?; - types::date_to_sql(jd as i32, w); + types::date_to_sql(jd, w); Ok(IsNull::No) } diff --git a/tokio-postgres/src/config.rs b/tokio-postgres/src/config.rs index 59edd8fe2..dfe34dea6 100644 --- a/tokio-postgres/src/config.rs +++ b/tokio-postgres/src/config.rs @@ -872,10 +872,8 @@ impl<'a> Parser<'a> { match self.it.next() { Some((_, c)) if c == target => Ok(()), Some((i, c)) => { - let m = format!( - "unexpected character at byte {}: expected `{}` but got `{}`", - i, target, c - ); + let m = + format!("unexpected character at byte {i}: expected `{target}` but got `{c}`"); Err(Error::config_parse(m.into())) } None => Err(Error::config_parse("unexpected EOF".into())), diff --git a/tokio-postgres/src/connect_socket.rs b/tokio-postgres/src/connect_socket.rs index 26184701f..0001cef19 100644 --- a/tokio-postgres/src/connect_socket.rs +++ b/tokio-postgres/src/connect_socket.rs @@ -45,7 +45,7 @@ pub(crate) async fn connect_socket( } #[cfg(unix)] Addr::Unix(dir) => { - let path = dir.join(format!(".s.PGSQL.{}", port)); + let path = dir.join(format!(".s.PGSQL.{port}")); let socket = connect_with_timeout(UnixStream::connect(path), connect_timeout).await?; Ok(Socket::new_unix(socket)) } diff --git a/tokio-postgres/src/error/mod.rs b/tokio-postgres/src/error/mod.rs index 75664d258..5d4c87eb0 100644 --- a/tokio-postgres/src/error/mod.rs +++ b/tokio-postgres/src/error/mod.rs @@ -312,10 +312,10 @@ impl fmt::Display for DbError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{}: {}", self.severity, self.message)?; if let Some(detail) = &self.detail { - write!(fmt, "\nDETAIL: {}", detail)?; + write!(fmt, "\nDETAIL: {detail}")?; } if let Some(hint) = &self.hint { - write!(fmt, "\nHINT: {}", hint)?; + write!(fmt, "\nHINT: {hint}")?; } Ok(()) } @@ -382,9 +382,9 @@ impl fmt::Display for Error { Kind::Io => fmt.write_str("error communicating with the server")?, Kind::UnexpectedMessage => fmt.write_str("unexpected message from server")?, Kind::Tls => fmt.write_str("error performing TLS handshake")?, - Kind::ToSql(idx) => write!(fmt, "error serializing parameter {}", idx)?, - Kind::FromSql(idx) => write!(fmt, "error deserializing column {}", idx)?, - Kind::Column(column) => write!(fmt, "invalid column `{}`", column)?, + Kind::ToSql(idx) => write!(fmt, "error serializing parameter {idx}")?, + Kind::FromSql(idx) => write!(fmt, "error deserializing column {idx}")?, + Kind::Column(column) => write!(fmt, "invalid column `{column}`")?, Kind::Parameters(real, expected) => { write!(fmt, "expected {expected} parameters but got {real}")? } @@ -401,7 +401,7 @@ impl fmt::Display for Error { Kind::Timeout => fmt.write_str("timeout waiting for server")?, }; if let Some(ref cause) = self.0.cause { - write!(fmt, ": {}", cause)?; + write!(fmt, ": {cause}")?; } Ok(()) } diff --git a/tokio-postgres/src/prepare.rs b/tokio-postgres/src/prepare.rs index 1d9bacb16..a238b6807 100644 --- a/tokio-postgres/src/prepare.rs +++ b/tokio-postgres/src/prepare.rs @@ -118,9 +118,9 @@ fn prepare_rec<'a>( fn encode(client: &InnerClient, name: &str, query: &str, types: &[Type]) -> Result { if types.is_empty() { - debug!("preparing query {}: {}", name, query); + debug!("preparing query {name}: {query}"); } else { - debug!("preparing query {} with types {:?}: {}", name, types, query); + debug!("preparing query {name} with types {types:?}: {query}"); } client.with_buf(|buf| { diff --git a/tokio-postgres/src/simple_query.rs b/tokio-postgres/src/simple_query.rs index 24473b896..d94bbde44 100644 --- a/tokio-postgres/src/simple_query.rs +++ b/tokio-postgres/src/simple_query.rs @@ -33,7 +33,7 @@ impl SimpleColumn { } pub async fn simple_query(client: &InnerClient, query: &str) -> Result { - debug!("executing simple query: {}", query); + debug!("executing simple query: {query}"); let buf = encode(client, query)?; let responses = client.send(RequestMessages::Single(FrontendMessage::Raw(buf)))?; @@ -46,7 +46,7 @@ pub async fn simple_query(client: &InnerClient, query: &str) -> Result Result<(), Error> { - debug!("executing statement batch: {}", query); + debug!("executing statement batch: {query}"); let buf = encode(client, query)?; let mut responses = client.send(RequestMessages::Single(FrontendMessage::Raw(buf)))?; diff --git a/tokio-postgres/src/transaction.rs b/tokio-postgres/src/transaction.rs index 782c476c4..de84a3611 100644 --- a/tokio-postgres/src/transaction.rs +++ b/tokio-postgres/src/transaction.rs @@ -314,8 +314,8 @@ impl<'a> Transaction<'a> { async fn _savepoint(&mut self, name: Option) -> Result, Error> { let depth = self.savepoint.as_ref().map_or(0, |sp| sp.depth) + 1; - let name = name.unwrap_or_else(|| format!("sp_{}", depth)); - let query = format!("SAVEPOINT {}", name); + let name = name.unwrap_or_else(|| format!("sp_{depth}")); + let query = format!("SAVEPOINT {name}"); self.batch_execute(&query).await?; Ok(Transaction { diff --git a/tokio-postgres/tests/test/binary_copy.rs b/tokio-postgres/tests/test/binary_copy.rs index 94b96ab85..712ee8e07 100644 --- a/tokio-postgres/tests/test/binary_copy.rs +++ b/tokio-postgres/tests/test/binary_copy.rs @@ -56,7 +56,7 @@ async fn write_many_rows() { for i in 0..10_000i32 { writer .as_mut() - .write(&[&i, &format!("the value for {}", i)]) + .write(&[&i, &format!("the value for {i}")]) .await .unwrap(); } @@ -69,7 +69,7 @@ async fn write_many_rows() { .unwrap(); for (i, row) in rows.iter().enumerate() { assert_eq!(row.get::<_, i32>(0), i as i32); - assert_eq!(row.get::<_, &str>(1), format!("the value for {}", i)); + assert_eq!(row.get::<_, &str>(1), format!("the value for {i}")); } } @@ -164,7 +164,7 @@ async fn read_many_rows() { for (i, row) in rows.iter().enumerate() { assert_eq!(row.get::(0), i as i32); - assert_eq!(row.get::<&str>(1), format!("the value for {}", i)); + assert_eq!(row.get::<&str>(1), format!("the value for {i}")); } } diff --git a/tokio-postgres/tests/test/main.rs b/tokio-postgres/tests/test/main.rs index 9a6aa26fe..bac008f08 100644 --- a/tokio-postgres/tests/test/main.rs +++ b/tokio-postgres/tests/test/main.rs @@ -624,11 +624,11 @@ async fn copy_in_large() { let a = Bytes::from_static(b"0\tname0\n"); let mut b = BytesMut::new(); for i in 1..5_000 { - writeln!(b, "{0}\tname{0}", i).unwrap(); + writeln!(b, "{i}\tname{i}").unwrap(); } let mut c = BytesMut::new(); for i in 5_000..10_000 { - writeln!(c, "{0}\tname{0}", i).unwrap(); + writeln!(c, "{i}\tname{i}").unwrap(); } let mut stream = stream::iter( vec![a, b.freeze(), c.freeze()] @@ -704,7 +704,7 @@ async fn copy_out() { async fn notices() { let long_name = "x".repeat(65); let (client, mut connection) = - connect_raw(&format!("user=postgres application_name={}", long_name,)) + connect_raw(&format!("user=postgres application_name={long_name}",)) .await .unwrap(); diff --git a/tokio-postgres/tests/test/parse.rs b/tokio-postgres/tests/test/parse.rs index 35eeca72b..68ce33bdf 100644 --- a/tokio-postgres/tests/test/parse.rs +++ b/tokio-postgres/tests/test/parse.rs @@ -2,7 +2,7 @@ use std::time::Duration; use tokio_postgres::config::{Config, SslNegotiation, TargetSessionAttrs}; fn check(s: &str, config: &Config) { - assert_eq!(s.parse::().expect(s), *config, "`{}`", s); + assert_eq!(s.parse::().expect(s), *config, "`{s}`"); } #[test] diff --git a/tokio-postgres/tests/test/types/chrono_04.rs b/tokio-postgres/tests/test/types/chrono_04.rs index eda8151a6..fd5c11a47 100644 --- a/tokio-postgres/tests/test/types/chrono_04.rs +++ b/tokio-postgres/tests/test/types/chrono_04.rs @@ -166,7 +166,7 @@ async fn test_special_params_without_wrapper() { T: FromSqlOwned + fmt::Debug, { let err = client - .query_one(&*format!("SELECT {}::{}", val, sql_type), &[]) + .query_one(&*format!("SELECT {val}::{sql_type}"), &[]) .await .unwrap() .try_get::<_, T>(0) diff --git a/tokio-postgres/tests/test/types/jiff_01.rs b/tokio-postgres/tests/test/types/jiff_01.rs index 7c9052676..1bd1e26e8 100644 --- a/tokio-postgres/tests/test/types/jiff_01.rs +++ b/tokio-postgres/tests/test/types/jiff_01.rs @@ -140,7 +140,7 @@ async fn test_special_params_without_wrapper() { T: FromSqlOwned + fmt::Debug, { let err = client - .query_one(&*format!("SELECT {}::{}", val, sql_type), &[]) + .query_one(&*format!("SELECT {val}::{sql_type}"), &[]) .await .unwrap() .try_get::<_, T>(0) @@ -152,7 +152,7 @@ async fn test_special_params_without_wrapper() { ); let err = client - .query_one(&*format!("SELECT {}::{}", val, sql_type), &[]) + .query_one(&*format!("SELECT {val}::{sql_type}"), &[]) .await .unwrap() .try_get::<_, T>(0) diff --git a/tokio-postgres/tests/test/types/jiff_02.rs b/tokio-postgres/tests/test/types/jiff_02.rs index d13185589..92f85e817 100644 --- a/tokio-postgres/tests/test/types/jiff_02.rs +++ b/tokio-postgres/tests/test/types/jiff_02.rs @@ -140,7 +140,7 @@ async fn test_special_params_without_wrapper() { T: FromSqlOwned + fmt::Debug, { let err = client - .query_one(&*format!("SELECT {}::{}", val, sql_type), &[]) + .query_one(&*format!("SELECT {val}::{sql_type}"), &[]) .await .unwrap() .try_get::<_, T>(0) @@ -152,7 +152,7 @@ async fn test_special_params_without_wrapper() { ); let err = client - .query_one(&*format!("SELECT {}::{}", val, sql_type), &[]) + .query_one(&*format!("SELECT {val}::{sql_type}"), &[]) .await .unwrap() .try_get::<_, T>(0) diff --git a/tokio-postgres/tests/test/types/mod.rs b/tokio-postgres/tests/test/types/mod.rs index 41c4a8899..c3a5735f1 100644 --- a/tokio-postgres/tests/test/types/mod.rs +++ b/tokio-postgres/tests/test/types/mod.rs @@ -49,14 +49,14 @@ where for (val, repr) in checks { let rows = client - .query(&*format!("SELECT {}::{}", repr, sql_type), &[]) + .query(&*format!("SELECT {repr}::{sql_type}"), &[]) .await .unwrap(); let result = rows[0].get(0); assert_eq!(val, &result); let rows = client - .query(&*format!("SELECT $1::{}", sql_type), &[&val]) + .query(&*format!("SELECT $1::{sql_type}"), &[&val]) .await .unwrap(); let result = rows[0].get(0); @@ -391,7 +391,7 @@ where let client = connect("user=postgres").await; let stmt = client - .prepare(&format!("SELECT 'NaN'::{}", sql_type)) + .prepare(&format!("SELECT 'NaN'::{sql_type}")) .await .unwrap(); let rows = client.query(&stmt, &[]).await.unwrap(); diff --git a/tokio-postgres/tests/test/types/time_03.rs b/tokio-postgres/tests/test/types/time_03.rs index fca940a97..5c499e7b6 100644 --- a/tokio-postgres/tests/test/types/time_03.rs +++ b/tokio-postgres/tests/test/types/time_03.rs @@ -161,7 +161,7 @@ async fn test_special_params_without_wrapper() { T: FromSqlOwned + fmt::Debug, { let err = client - .query_one(&*format!("SELECT {}::{}", val, sql_type), &[]) + .query_one(&*format!("SELECT {val}::{sql_type}"), &[]) .await .unwrap() .try_get::<_, T>(0)