Skip to content

Commit 609db87

Browse files
committed
fix: resolve clippy warnings in query, io, and tls modules
- Fix reference to reference pattern in query.rs - Remove redundant closure using and_then directly - Remove needless borrows in io/buf.rs and logger.rs - Replace iter().cloned().collect() with to_vec() for better performance - Use std::io::Error::other() instead of Error::new(ErrorKind::Other)
1 parent e23d880 commit 609db87

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

sqlx-core/src/io/buf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub trait BufExt: Buf {
2222
impl BufExt for Bytes {
2323
fn get_bytes_nul(&mut self) -> Result<Bytes, Error> {
2424
let nul =
25-
memchr(b'\0', &self).ok_or_else(|| err_protocol!("expected NUL in byte sequence"))?;
25+
memchr(b'\0', self).ok_or_else(|| err_protocol!("expected NUL in byte sequence"))?;
2626

2727
let v = self.slice(0..nul);
2828

@@ -40,7 +40,7 @@ impl BufExt for Bytes {
4040

4141
fn get_str_nul(&mut self) -> Result<String, Error> {
4242
self.get_bytes_nul().and_then(|bytes| {
43-
from_utf8(&*bytes)
43+
from_utf8(&bytes)
4444
.map(ToOwned::to_owned)
4545
.map_err(|err| err_protocol!("{}", err))
4646
})

sqlx-core/src/logger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'q> QueryLogger<'q> {
4747
.to_level()
4848
.filter(|lvl| log::log_enabled!(target: "sqlx::query", *lvl))
4949
{
50-
let mut summary = parse_query_summary(&self.sql);
50+
let mut summary = parse_query_summary(self.sql);
5151

5252
let sql = if summary != self.sql {
5353
summary.push_str(" …");
@@ -126,7 +126,7 @@ impl<'q, O: Debug + Hash + Eq, R: Debug, P: Debug> QueryPlanLogger<'q, O, R, P>
126126
.to_level()
127127
.filter(|lvl| log::log_enabled!(target: "sqlx::explain", *lvl))
128128
{
129-
let mut summary = parse_query_summary(&self.sql);
129+
let mut summary = parse_query_summary(self.sql);
130130

131131
let sql = if summary != self.sql {
132132
summary.push_str(" …");

sqlx-core/src/net/tls/rustls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ pub async fn configure_tls_connector(
7272
.with_custom_certificate_verifier(Arc::new(DummyTlsVerifier))
7373
} else {
7474
let mut cert_store = RootCertStore {
75-
roots: webpki_roots::TLS_SERVER_ROOTS.iter().cloned().collect(),
75+
roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),
7676
};
7777

7878
if let Some(ca) = tls_config.root_cert_path {
7979
let path_description = ca.to_string();
8080
let data = ca.data().await.map_err(|e| RustlsError::ParsePemCert {
8181
file_description: path_description.clone(),
82-
source: std::io::Error::new(std::io::ErrorKind::Other, e),
82+
source: std::io::Error::other(e),
8383
})?;
8484
let mut cursor = Cursor::new(data);
8585

@@ -116,13 +116,13 @@ pub async fn configure_tls_connector(
116116
let cert_chain = certs_from_pem(cert_path.data().await.map_err(|e| {
117117
RustlsError::ParseClientCert {
118118
file_description: cert_file_desc.clone(),
119-
source: std::io::Error::new(std::io::ErrorKind::Other, e),
119+
source: std::io::Error::other(e),
120120
}
121121
})?)?;
122122
let key_der = private_key_from_pem(key_path.data().await.map_err(|e| {
123123
RustlsError::ParseClientKey {
124124
file_description: key_file_desc.clone(),
125-
source: std::io::Error::new(std::io::ErrorKind::Other, e),
125+
source: std::io::Error::other(e),
126126
}
127127
})?)?;
128128
config

sqlx-core/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ where
5151

5252
fn statement(&self) -> Option<&<DB as HasStatement<'q>>::Statement> {
5353
match self.statement {
54-
Either::Right(ref statement) => Some(&statement),
54+
Either::Right(ref statement) => Some(statement),
5555
Either::Left(_) => None,
5656
}
5757
}
@@ -293,7 +293,7 @@ where
293293
let mut f = self.mapper;
294294
Map {
295295
inner: self.inner,
296-
mapper: move |row| f(row).and_then(|o| g(o)),
296+
mapper: move |row| f(row).and_then(g),
297297
}
298298
}
299299

0 commit comments

Comments
 (0)