From f686b916938f263708fc6c4e28adc154c616a763 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Wed, 21 Aug 2024 15:57:21 +0000 Subject: [PATCH] clippy --- .../inmemory_layer/vectored_dio_read.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pageserver/src/tenant/storage_layer/inmemory_layer/vectored_dio_read.rs b/pageserver/src/tenant/storage_layer/inmemory_layer/vectored_dio_read.rs index c0aabd1f4d..da4830c9cf 100644 --- a/pageserver/src/tenant/storage_layer/inmemory_layer/vectored_dio_read.rs +++ b/pageserver/src/tenant/storage_layer/inmemory_layer/vectored_dio_read.rs @@ -112,7 +112,7 @@ where // transition from NotStarted to Ongoing let cur = std::mem::replace(&mut *state, LogicalReadState::Undefined); - let remaining = match cur { + let req_len = match cur { LogicalReadState::NotStarted(buf) => { if buf.len() != 0 { panic!("The `LogicalRead`s that are passed in must be freshly created using `LogicalRead::new`"); @@ -120,15 +120,15 @@ where // buf.cap() == 0 is ok // transition into Ongoing state - let remaining = buf.cap(); + let req_len = buf.cap(); *state = LogicalReadState::Ongoing(buf); - remaining + req_len } x => panic!("must only call with fresh LogicalReads, got another state, leaving Undefined state behind state={x:?}"), }; // plan which chunks we need to read from - let mut remaining = usize::try_from(remaining).unwrap(); + let mut remaining = req_len; let mut chunk_no = *pos / (DIO_CHUNK_SIZE as u32); let mut offset_in_chunk = usize::try_from(*pos % (DIO_CHUNK_SIZE as u32)).unwrap(); while remaining > 0 { @@ -406,6 +406,7 @@ impl Buffer for Vec { } #[cfg(test)] +#[allow(clippy::assertions_on_constants)] mod tests { use rand::Rng; @@ -432,7 +433,7 @@ mod tests { } fn test_logical_read(&self, pos: u32, len: usize) -> TestLogicalRead { let expected_result = if pos as usize + len > self.content.len() { - Err(format!("InMemoryFile short read")) + Err("InMemoryFile short read".to_string()) } else { Ok(self.content[pos as usize..pos as usize + len].to_vec()) }; @@ -517,7 +518,7 @@ mod tests { { let (tmp, test_logical_reads) = test_logical_reads.into_iter().tee(); let logical_reads = tmp.map(|tr| tr.make_logical_read()).collect::>(); - execute(file, logical_reads.iter(), &ctx).await; + execute(file, logical_reads.iter(), ctx).await; for (logical_read, test_logical_read) in logical_reads.into_iter().zip(test_logical_reads) { let actual = logical_read.into_result().expect("we call execute()"); match (actual, test_logical_read.expected_result) { @@ -830,7 +831,7 @@ mod tests { for test_logical_reads in test_logical_read_perms { let file = mock_file!( - 0 * DIO_CHUNK_SIZE as u32, MAX_CHUNK_BATCH_SIZE*DIO_CHUNK_SIZE => Ok(vec![0; MAX_CHUNK_BATCH_SIZE*DIO_CHUNK_SIZE]), + 0, MAX_CHUNK_BATCH_SIZE*DIO_CHUNK_SIZE => Ok(vec![0; MAX_CHUNK_BATCH_SIZE*DIO_CHUNK_SIZE]), (MAX_CHUNK_BATCH_SIZE*DIO_CHUNK_SIZE) as u32, DIO_CHUNK_SIZE => Err("foo".to_owned()), (MAX_CHUNK_BATCH_SIZE*DIO_CHUNK_SIZE + 2*DIO_CHUNK_SIZE) as u32, DIO_CHUNK_SIZE => Ok(vec![1; DIO_CHUNK_SIZE]), );