From 3e67dbb773d7af47e0d19d9dc3688fc5db731c0c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Wed, 10 Jun 2020 16:54:07 -0700 Subject: [PATCH] Fix clippy --- codegen/src/type_gen.rs | 45 +++++++++++----------------- postgres/src/copy_out_reader.rs | 2 +- tokio-postgres/src/error/mod.rs | 20 ++++++------- tokio-postgres/src/generic_client.rs | 1 + 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/codegen/src/type_gen.rs b/codegen/src/type_gen.rs index 99a38ce8..010b30c5 100644 --- a/codegen/src/type_gen.rs +++ b/codegen/src/type_gen.rs @@ -319,46 +319,42 @@ fn make_impl(w: &mut BufWriter, types: &BTreeMap) { .unwrap(); for (oid, type_) in types { - write!( + writeln!( w, - " {} => Some(Inner::{}), -", + " {} => Some(Inner::{}),", oid, type_.variant ) .unwrap(); } - write!( + writeln!( w, " _ => None, }} }} pub fn oid(&self) -> Oid {{ - match *self {{ -", + match *self {{", ) .unwrap(); for (oid, type_) in types { - write!( + writeln!( w, - " Inner::{} => {}, -", + " Inner::{} => {},", type_.variant, oid ) .unwrap(); } - write!( + writeln!( w, " Inner::Other(ref u) => u.oid, }} }} pub fn kind(&self) -> &Kind {{ - match *self {{ -", + match *self {{", ) .unwrap(); @@ -370,46 +366,42 @@ fn make_impl(w: &mut BufWriter, types: &BTreeMap) { _ => "Simple".to_owned(), }; - write!( + writeln!( w, " Inner::{} => {{ &Kind::{} - }} -", + }}", type_.variant, kind ) .unwrap(); } - write!( + writeln!( w, r#" Inner::Other(ref u) => &u.kind, }} }} pub fn name(&self) -> &str {{ - match *self {{ -"#, + match *self {{"#, ) .unwrap(); for type_ in types.values() { - write!( + writeln!( w, - r#" Inner::{} => "{}", -"#, + r#" Inner::{} => "{}","#, type_.variant, type_.name ) .unwrap(); } - write!( + writeln!( w, " Inner::Other(ref u) => &u.name, }} }} -}} -" +}}" ) .unwrap(); } @@ -417,12 +409,11 @@ fn make_impl(w: &mut BufWriter, types: &BTreeMap) { fn make_consts(w: &mut BufWriter, types: &BTreeMap) { write!(w, "impl Type {{").unwrap(); for type_ in types.values() { - write!( + writeln!( w, " /// {docs} - pub const {ident}: Type = Type(Inner::{variant}); -", + pub const {ident}: Type = Type(Inner::{variant});", docs = type_.doc, ident = type_.ident, variant = type_.variant diff --git a/postgres/src/copy_out_reader.rs b/postgres/src/copy_out_reader.rs index 92abebce..fd9c27fb 100644 --- a/postgres/src/copy_out_reader.rs +++ b/postgres/src/copy_out_reader.rs @@ -38,7 +38,7 @@ impl BufRead for CopyOutReader<'_> { let mut stream = self.stream.pinned(); match self .connection - .block_on({ async { stream.next().await.transpose() } }) + .block_on(async { stream.next().await.transpose() }) { Ok(Some(cur)) => self.cur = cur, Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)), diff --git a/tokio-postgres/src/error/mod.rs b/tokio-postgres/src/error/mod.rs index 788e70cf..0bcf0c6f 100644 --- a/tokio-postgres/src/error/mod.rs +++ b/tokio-postgres/src/error/mod.rs @@ -224,7 +224,7 @@ impl DbError { /// /// Might run to multiple lines. pub fn detail(&self) -> Option<&str> { - self.detail.as_ref().map(|s| &**s) + self.detail.as_deref() } /// An optional suggestion what to do about the problem. @@ -233,7 +233,7 @@ impl DbError { /// (potentially inappropriate) rather than hard facts. Might run to /// multiple lines. pub fn hint(&self) -> Option<&str> { - self.hint.as_ref().map(|s| &**s) + self.hint.as_deref() } /// An optional error cursor position into either the original query string @@ -248,20 +248,20 @@ impl DbError { /// language functions and internally-generated queries. The trace is one /// entry per line, most recent first. pub fn where_(&self) -> Option<&str> { - self.where_.as_ref().map(|s| &**s) + self.where_.as_deref() } /// If the error was associated with a specific database object, the name /// of the schema containing that object, if any. (PostgreSQL 9.3+) pub fn schema(&self) -> Option<&str> { - self.schema.as_ref().map(|s| &**s) + self.schema.as_deref() } /// If the error was associated with a specific table, the name of the /// table. (Refer to the schema name field for the name of the table's /// schema.) (PostgreSQL 9.3+) pub fn table(&self) -> Option<&str> { - self.table.as_ref().map(|s| &**s) + self.table.as_deref() } /// If the error was associated with a specific table column, the name of @@ -270,14 +270,14 @@ impl DbError { /// (Refer to the schema and table name fields to identify the table.) /// (PostgreSQL 9.3+) pub fn column(&self) -> Option<&str> { - self.column.as_ref().map(|s| &**s) + self.column.as_deref() } /// If the error was associated with a specific data type, the name of the /// data type. (Refer to the schema name field for the name of the data /// type's schema.) (PostgreSQL 9.3+) pub fn datatype(&self) -> Option<&str> { - self.datatype.as_ref().map(|s| &**s) + self.datatype.as_deref() } /// If the error was associated with a specific constraint, the name of the @@ -287,12 +287,12 @@ impl DbError { /// (For this purpose, indexes are treated as constraints, even if they /// weren't created with constraint syntax.) (PostgreSQL 9.3+) pub fn constraint(&self) -> Option<&str> { - self.constraint.as_ref().map(|s| &**s) + self.constraint.as_deref() } /// The file name of the source-code location where the error was reported. pub fn file(&self) -> Option<&str> { - self.file.as_ref().map(|s| &**s) + self.file.as_deref() } /// The line number of the source-code location where the error was @@ -303,7 +303,7 @@ impl DbError { /// The name of the source-code routine reporting the error. pub fn routine(&self) -> Option<&str> { - self.routine.as_ref().map(|s| &**s) + self.routine.as_deref() } } diff --git a/tokio-postgres/src/generic_client.rs b/tokio-postgres/src/generic_client.rs index 30351bd0..ad318e86 100644 --- a/tokio-postgres/src/generic_client.rs +++ b/tokio-postgres/src/generic_client.rs @@ -146,6 +146,7 @@ impl GenericClient for Client { impl private::Sealed for Transaction<'_> {} #[async_trait] +#[allow(clippy::needless_lifetimes)] impl GenericClient for Transaction<'_> { async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result where