Skip to content

Commit 72832b3

Browse files
chore: fix clippy lints from nightly-2025-03-16 (#11273)
I like to run nightly clippy every so often to make our future rust upgrades easier. Some notable changes: * Prefer `next_back()` over `last()`. Generic iterators will implement `last()` to run forward through the iterator until the end. * Prefer `io::Error::other()`. * Use implicit returns One case where I haven't dealt with the issues is the now [more-sensitive "large enum variant" lint](rust-lang/rust-clippy#13833). I chose not to take any decisions around it here, and simply marked them as allow for now.
1 parent d11f23a commit 72832b3

File tree

25 files changed

+57
-67
lines changed

25 files changed

+57
-67
lines changed

compute_tools/src/catalog.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ pub async fn get_database_schema(
9898
.kill_on_drop(true)
9999
.spawn()?;
100100

101-
let stdout = cmd.stdout.take().ok_or_else(|| {
102-
std::io::Error::new(std::io::ErrorKind::Other, "Failed to capture stdout.")
103-
})?;
101+
let stdout = cmd
102+
.stdout
103+
.take()
104+
.ok_or_else(|| std::io::Error::other("Failed to capture stdout."))?;
104105

105-
let stderr = cmd.stderr.take().ok_or_else(|| {
106-
std::io::Error::new(std::io::ErrorKind::Other, "Failed to capture stderr.")
107-
})?;
106+
let stderr = cmd
107+
.stderr
108+
.take()
109+
.ok_or_else(|| std::io::Error::other("Failed to capture stderr."))?;
108110

109111
let mut stdout_reader = FramedRead::new(stdout, BytesCodec::new());
110112
let stderr_reader = BufReader::new(stderr);
@@ -128,8 +130,7 @@ pub async fn get_database_schema(
128130
}
129131
});
130132

131-
return Err(SchemaDumpError::IO(std::io::Error::new(
132-
std::io::ErrorKind::Other,
133+
return Err(SchemaDumpError::IO(std::io::Error::other(
133134
"failed to start pg_dump",
134135
)));
135136
}

control_plane/storcon_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ async fn main() -> anyhow::Result<()> {
941941
let mut node_to_fill_descs = Vec::new();
942942

943943
for desc in node_descs {
944-
let to_drain = nodes.iter().any(|id| *id == desc.id);
944+
let to_drain = nodes.contains(&desc.id);
945945
if to_drain {
946946
node_to_drain_descs.push(desc);
947947
} else {

libs/postgres_backend/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![deny(unsafe_code)]
66
#![deny(clippy::undocumented_unsafe_blocks)]
77
use std::future::Future;
8-
use std::io::ErrorKind;
98
use std::net::SocketAddr;
109
use std::os::fd::{AsRawFd, RawFd};
1110
use std::pin::Pin;
@@ -227,7 +226,7 @@ impl<IO: AsyncRead + AsyncWrite + Unpin> MaybeWriteOnly<IO> {
227226
match self {
228227
MaybeWriteOnly::Full(framed) => framed.read_startup_message().await,
229228
MaybeWriteOnly::WriteOnly(_) => {
230-
Err(io::Error::new(ErrorKind::Other, "reading from write only half").into())
229+
Err(io::Error::other("reading from write only half").into())
231230
}
232231
MaybeWriteOnly::Broken => panic!("IO on invalid MaybeWriteOnly"),
233232
}
@@ -237,7 +236,7 @@ impl<IO: AsyncRead + AsyncWrite + Unpin> MaybeWriteOnly<IO> {
237236
match self {
238237
MaybeWriteOnly::Full(framed) => framed.read_message().await,
239238
MaybeWriteOnly::WriteOnly(_) => {
240-
Err(io::Error::new(ErrorKind::Other, "reading from write only half").into())
239+
Err(io::Error::other("reading from write only half").into())
241240
}
242241
MaybeWriteOnly::Broken => panic!("IO on invalid MaybeWriteOnly"),
243242
}
@@ -975,7 +974,7 @@ impl<IO: AsyncRead + AsyncWrite + Unpin> AsyncWrite for CopyDataWriter<'_, IO> {
975974
.write_message_noflush(&BeMessage::CopyData(buf))
976975
// write_message only writes to the buffer, so it can fail iff the
977976
// message is invaid, but CopyData can't be invalid.
978-
.map_err(|_| io::Error::new(ErrorKind::Other, "failed to serialize CopyData"))?;
977+
.map_err(|_| io::Error::other("failed to serialize CopyData"))?;
979978

980979
Poll::Ready(Ok(buf.len()))
981980
}

libs/postgres_backend/tests/simple_select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ static KEY: Lazy<rustls::pki_types::PrivateKeyDer<'static>> = Lazy::new(|| {
8585

8686
static CERT: Lazy<rustls::pki_types::CertificateDer<'static>> = Lazy::new(|| {
8787
let mut cursor = Cursor::new(include_bytes!("cert.pem"));
88-
let cert = rustls_pemfile::certs(&mut cursor).next().unwrap().unwrap();
89-
cert
88+
89+
rustls_pemfile::certs(&mut cursor).next().unwrap().unwrap()
9090
});
9191

9292
// test that basic select with ssl works

libs/pq_proto/src/framed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl ConnectionError {
3535
pub fn into_io_error(self) -> io::Error {
3636
match self {
3737
ConnectionError::Io(io) => io,
38-
ConnectionError::Protocol(pe) => io::Error::new(io::ErrorKind::Other, pe.to_string()),
38+
ConnectionError::Protocol(pe) => io::Error::other(pe.to_string()),
3939
}
4040
}
4141
}

libs/pq_proto/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub enum ProtocolError {
257257
impl ProtocolError {
258258
/// Proxy stream.rs uses only io::Error; provide it.
259259
pub fn into_io_error(self) -> io::Error {
260-
io::Error::new(io::ErrorKind::Other, self.to_string())
260+
io::Error::other(self.to_string())
261261
}
262262
}
263263

libs/proxy/postgres-protocol2/src/authentication/sasl.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl ScramSha256 {
212212
password,
213213
channel_binding,
214214
} => (nonce, password, channel_binding),
215-
_ => return Err(io::Error::new(io::ErrorKind::Other, "invalid SCRAM state")),
215+
_ => return Err(io::Error::other("invalid SCRAM state")),
216216
};
217217

218218
let message =
@@ -291,7 +291,7 @@ impl ScramSha256 {
291291
server_key,
292292
auth_message,
293293
} => (server_key, auth_message),
294-
_ => return Err(io::Error::new(io::ErrorKind::Other, "invalid SCRAM state")),
294+
_ => return Err(io::Error::other("invalid SCRAM state")),
295295
};
296296

297297
let message =
@@ -301,10 +301,7 @@ impl ScramSha256 {
301301

302302
let verifier = match parsed {
303303
ServerFinalMessage::Error(e) => {
304-
return Err(io::Error::new(
305-
io::ErrorKind::Other,
306-
format!("SCRAM error: {}", e),
307-
));
304+
return Err(io::Error::other(format!("SCRAM error: {}", e)));
308305
}
309306
ServerFinalMessage::Verifier(verifier) => verifier,
310307
};

libs/remote_storage/src/azure_blob.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,7 @@ where
801801
// that support needs to be hacked in.
802802
//
803803
// including {self:?} into the message would be useful, but unsure how to unproject.
804-
_ => std::task::Poll::Ready(Err(std::io::Error::new(
805-
std::io::ErrorKind::Other,
804+
_ => std::task::Poll::Ready(Err(std::io::Error::other(
806805
"cloned or initial values cannot be read",
807806
))),
808807
}
@@ -855,7 +854,7 @@ where
855854
};
856855
Err(azure_core::error::Error::new(
857856
azure_core::error::ErrorKind::Io,
858-
std::io::Error::new(std::io::ErrorKind::Other, msg),
857+
std::io::Error::other(msg),
859858
))
860859
}
861860

libs/utils/src/crashsafe.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ pub fn path_with_suffix_extension(
8181
}
8282

8383
pub fn fsync_file_and_parent(file_path: &Utf8Path) -> io::Result<()> {
84-
let parent = file_path.parent().ok_or_else(|| {
85-
io::Error::new(
86-
io::ErrorKind::Other,
87-
format!("File {file_path:?} has no parent"),
88-
)
89-
})?;
84+
let parent = file_path
85+
.parent()
86+
.ok_or_else(|| io::Error::other(format!("File {file_path:?} has no parent")))?;
9087

9188
fsync(file_path)?;
9289
fsync(parent)?;

pageserver/src/http/routes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,11 +3381,11 @@ async fn put_tenant_timeline_import_basebackup(
33813381

33823382
let broker_client = state.broker_client.clone();
33833383

3384-
let mut body = StreamReader::new(request.into_body().map(|res| {
3385-
res.map_err(|error| {
3386-
std::io::Error::new(std::io::ErrorKind::Other, anyhow::anyhow!(error))
3387-
})
3388-
}));
3384+
let mut body = StreamReader::new(
3385+
request
3386+
.into_body()
3387+
.map(|res| res.map_err(|error| std::io::Error::other(anyhow::anyhow!(error)))),
3388+
);
33893389

33903390
tenant.wait_to_become_active(ACTIVE_TENANT_TIMEOUT).await?;
33913391

@@ -3459,7 +3459,7 @@ async fn put_tenant_timeline_import_wal(
34593459

34603460
let mut body = StreamReader::new(request.into_body().map(|res| {
34613461
res.map_err(|error| {
3462-
std::io::Error::new(std::io::ErrorKind::Other, anyhow::anyhow!(error))
3462+
std::io::Error::other( anyhow::anyhow!(error))
34633463
})
34643464
}));
34653465

0 commit comments

Comments
 (0)