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

pageserver/src/tenant.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ enum StartCreatingTimelineResult {
920920
Idempotent(Arc<Timeline>),
921921
}
922922

923+
#[allow(clippy::large_enum_variant, reason = "TODO")]
923924
enum TimelineInitAndSyncResult {
924925
ReadyToActivate(Arc<Timeline>),
925926
NeedsSpawnImportPgdata(TimelineInitAndSyncNeedsSpawnImportPgdata),
@@ -1006,6 +1007,7 @@ enum CreateTimelineCause {
10061007
Delete,
10071008
}
10081009

1010+
#[allow(clippy::large_enum_variant, reason = "TODO")]
10091011
enum LoadTimelineCause {
10101012
Attach,
10111013
Unoffload,
@@ -4399,10 +4401,7 @@ impl Tenant {
43994401
.to_string();
44004402

44014403
fail::fail_point!("tenant-config-before-write", |_| {
4402-
Err(std::io::Error::new(
4403-
std::io::ErrorKind::Other,
4404-
"tenant-config-before-write",
4405-
))
4404+
Err(std::io::Error::other("tenant-config-before-write"))
44064405
});
44074406

44084407
// Convert the config to a toml file.

pageserver/src/tenant/blob_io.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! len >= 128: 1CCCXXXX XXXXXXXX XXXXXXXX XXXXXXXX
1616
//!
1717
use std::cmp::min;
18-
use std::io::{Error, ErrorKind};
18+
use std::io::Error;
1919

2020
use async_compression::Level;
2121
use bytes::{BufMut, BytesMut};
@@ -331,10 +331,7 @@ impl<const BUFFERED: bool> BlobWriter<BUFFERED> {
331331
return (
332332
(
333333
io_buf.slice_len(),
334-
Err(Error::new(
335-
ErrorKind::Other,
336-
format!("blob too large ({len} bytes)"),
337-
)),
334+
Err(Error::other(format!("blob too large ({len} bytes)"))),
338335
),
339336
srcbuf,
340337
);

pageserver/src/tenant/block_io.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,8 @@ impl<'a> FileBlockReader<'a> {
216216
match cache
217217
.read_immutable_buf(self.file_id, blknum, ctx)
218218
.await
219-
.map_err(|e| {
220-
std::io::Error::new(
221-
std::io::ErrorKind::Other,
222-
format!("Failed to read immutable buf: {e:#}"),
223-
)
224-
})? {
219+
.map_err(|e| std::io::Error::other(format!("Failed to read immutable buf: {e:#}")))?
220+
{
225221
ReadBufResult::Found(guard) => Ok(guard.into()),
226222
ReadBufResult::NotFound(write_guard) => {
227223
// Read the page from disk into the buffer

pageserver/src/tenant/storage_layer/batch_split_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl SplitDeltaLayerWriter {
366366
)
367367
.await?;
368368
let (start_key, prev_delta_writer) =
369-
std::mem::replace(&mut self.inner, Some((key, next_delta_writer))).unwrap();
369+
self.inner.replace((key, next_delta_writer)).unwrap();
370370
self.batches.add_unfinished_delta_writer(
371371
prev_delta_writer,
372372
start_key..key,

pageserver/src/tenant/storage_layer/inmemory_layer/vectored_dio_read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ mod tests {
766766
rand::Rng::fill(&mut rand::thread_rng(), &mut dst_slice[len..]); // to discover bugs
767767
Ok((dst, len))
768768
}
769-
Err(e) => Err(std::io::Error::new(std::io::ErrorKind::Other, e)),
769+
Err(e) => Err(std::io::Error::other(e)),
770770
}
771771
}
772772
}

pageserver/src/tenant/storage_layer/merge_iterator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl LayerIterRef<'_> {
5959
/// 1. Unified iterator for image and delta layers.
6060
/// 2. `Ord` for use in [`MergeIterator::heap`] (for the k-merge).
6161
/// 3. Lazy creation of the real delta/image iterator.
62+
#[allow(clippy::large_enum_variant, reason = "TODO")]
6263
pub(crate) enum IteratorWrapper<'a> {
6364
NotLoaded {
6465
ctx: &'a RequestContext,

pageserver/src/tenant/timeline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ pub(crate) enum ShutdownMode {
10391039
Hard,
10401040
}
10411041

1042+
#[allow(clippy::large_enum_variant, reason = "TODO")]
10421043
enum ImageLayerCreationOutcome {
10431044
/// We generated an image layer
10441045
Generated {

pageserver/src/tenant/upload_queue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ pub struct UploadQueueStoppedDeletable {
302302
pub(super) deleted_at: SetDeletedFlagProgress,
303303
}
304304

305+
#[allow(clippy::large_enum_variant, reason = "TODO")]
305306
pub enum UploadQueueStopped {
306307
Deletable(UploadQueueStoppedDeletable),
307308
Uninitialized,

proxy/src/cancellation.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,7 @@ impl CancelClosure {
425425
&mut mk_tls,
426426
&self.hostname,
427427
)
428-
.map_err(|e| {
429-
CancelError::IO(std::io::Error::new(
430-
std::io::ErrorKind::Other,
431-
e.to_string(),
432-
))
433-
})?;
428+
.map_err(|e| CancelError::IO(std::io::Error::other(e.to_string())))?;
434429

435430
self.cancel_token.cancel_query_raw(socket, tls).await?;
436431
debug!("query was cancelled");

proxy/src/proxy/tests/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ fn helper_create_cached_node_info(cache: &'static NodeInfoCache) -> CachedNodeIn
568568
fn helper_create_connect_info(
569569
mechanism: &TestConnectMechanism,
570570
) -> auth::Backend<'static, ComputeCredentials> {
571-
let user_info = auth::Backend::ControlPlane(
571+
auth::Backend::ControlPlane(
572572
MaybeOwned::Owned(ControlPlaneClient::Test(Box::new(mechanism.clone()))),
573573
ComputeCredentials {
574574
info: ComputeUserInfo {
@@ -578,8 +578,7 @@ fn helper_create_connect_info(
578578
},
579579
keys: ComputeCredentialKeys::Password("password".into()),
580580
},
581-
);
582-
user_info
581+
)
583582
}
584583

585584
fn config() -> ComputeConfig {

proxy/src/serverless/conn_pool_lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl ConnInfo {
4747
}
4848

4949
#[derive(Clone)]
50+
#[allow(clippy::large_enum_variant, reason = "TODO")]
5051
pub(crate) enum ClientDataEnum {
5152
Remote(ClientDataRemote),
5253
Local(ClientDataLocal),

safekeeper/src/timeline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ impl Drop for WriteGuardSharedState<'_> {
138138
/// Usually it holds SafeKeeper, but it also supports offloaded timeline state. In this
139139
/// case, SafeKeeper is not available (because WAL is not present on disk) and all
140140
/// operations can be done only with control file.
141+
#[allow(clippy::large_enum_variant, reason = "TODO")]
141142
pub enum StateSK {
142143
Loaded(SafeKeeper<control_file::FileStorage, wal_storage::PhysicalStorage>),
143144
Offloaded(Box<TimelineState<control_file::FileStorage>>),

safekeeper/src/timeline_eviction.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Manager {
3535
next_event: &Option<tokio::time::Instant>,
3636
state: &StateSnapshot,
3737
) -> bool {
38-
let ready = self.backup_task.is_none()
38+
self.backup_task.is_none()
3939
&& self.recovery_task.is_none()
4040
&& self.wal_removal_task.is_none()
4141
&& self.partial_backup_task.is_none()
@@ -61,8 +61,7 @@ impl Manager {
6161
.unwrap()
6262
.flush_lsn
6363
.segment_number(self.wal_seg_size)
64-
== self.last_removed_segno + 1;
65-
ready
64+
== self.last_removed_segno + 1
6665
}
6766

6867
/// Evict the timeline to remote storage. Returns whether the eviction was successful.

0 commit comments

Comments
 (0)