From aeff5964d9a3ad1f93157bd2902d743c0f43c36c Mon Sep 17 00:00:00 2001 From: xxchan Date: Tue, 13 Feb 2024 16:05:04 +0800 Subject: [PATCH] chore: fix nightly clippy (#15088) --- src/common/src/session_config/sink_decouple.rs | 18 +++++++++++------- src/connector/src/source/pulsar/topic.rs | 7 ++++--- src/connector/src/source/reader/fs_reader.rs | 2 +- src/expr/core/src/expr/build.rs | 1 + src/expr/macro/src/parse.rs | 4 +--- src/meta/src/barrier/progress.rs | 2 +- .../picker/manual_compaction_picker.rs | 6 +++--- .../picker/min_overlap_compaction_picker.rs | 2 +- .../picker/space_reclaim_compaction_picker.rs | 4 ++-- .../picker/ttl_reclaim_compaction_picker.rs | 4 ++-- .../compaction/selector/level_selector.rs | 16 ++++++++-------- src/storage/benches/bench_fs_operation.rs | 2 ++ src/storage/hummock_test/src/test_utils.rs | 2 ++ src/storage/hummock_trace/src/write.rs | 7 ------- src/storage/src/hummock/block_cache.rs | 6 +++--- .../src/common/table/state_table_cache.rs | 12 ++++++------ src/stream/src/executor/top_n/top_n_plain.rs | 8 ++++---- src/stream/src/executor/top_n/top_n_state.rs | 6 +++--- src/utils/pgwire/src/pg_server.rs | 2 +- 19 files changed, 56 insertions(+), 55 deletions(-) diff --git a/src/common/src/session_config/sink_decouple.rs b/src/common/src/session_config/sink_decouple.rs index fbb7f684ccabf..19f2a8ec81561 100644 --- a/src/common/src/session_config/sink_decouple.rs +++ b/src/common/src/session_config/sink_decouple.rs @@ -38,12 +38,16 @@ impl FromStr for SinkDecouple { } } -impl ToString for SinkDecouple { - fn to_string(&self) -> String { - match self { - Self::Default => "default".to_string(), - Self::Enable => "enable".to_string(), - Self::Disable => "disable".to_string(), - } +impl std::fmt::Display for SinkDecouple { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Self::Default => "default", + Self::Enable => "enable", + Self::Disable => "disable", + } + ) } } diff --git a/src/connector/src/source/pulsar/topic.rs b/src/connector/src/source/pulsar/topic.rs index 8c6ec41022b0a..4512662d6252c 100644 --- a/src/connector/src/source/pulsar/topic.rs +++ b/src/connector/src/source/pulsar/topic.rs @@ -32,9 +32,10 @@ pub struct Topic { pub partition_index: Option, } -impl ToString for Topic { - fn to_string(&self) -> String { - format!( +impl std::fmt::Display for Topic { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, "{}://{}/{}/{}", self.domain, self.tenant, self.namespace, self.topic ) diff --git a/src/connector/src/source/reader/fs_reader.rs b/src/connector/src/source/reader/fs_reader.rs index 5b199c8d8955b..f64a9def6aab6 100644 --- a/src/connector/src/source/reader/fs_reader.rs +++ b/src/connector/src/source/reader/fs_reader.rs @@ -72,7 +72,7 @@ impl FsSourceReader { .with_context(|| { format!("Failed to find column id: {} in source: {:?}", id, self) }) - .map(|col| col.clone()) + .cloned() }) .try_collect() } diff --git a/src/expr/core/src/expr/build.rs b/src/expr/core/src/expr/build.rs index 51e9b87de19fe..91ebe67f479a9 100644 --- a/src/expr/core/src/expr/build.rs +++ b/src/expr/core/src/expr/build.rs @@ -131,6 +131,7 @@ pub(crate) trait Build: Expression + Sized { /// Build the expression `Self` from protobuf for test, where each child is built with /// [`build_from_prost`]. + #[cfg(test)] fn build_for_test(prost: &ExprNode) -> Result { Self::build(prost, build_from_prost) } diff --git a/src/expr/macro/src/parse.rs b/src/expr/macro/src/parse.rs index d5b1ddf57fffb..30976e14f1925 100644 --- a/src/expr/macro/src/parse.rs +++ b/src/expr/macro/src/parse.rs @@ -280,9 +280,7 @@ fn strip_outer_type<'a>(ty: &'a syn::Type, type_: &str) -> Option<&'a syn::Type> let syn::Type::Path(path) = ty else { return None; }; - let Some(seg) = path.path.segments.last() else { - return None; - }; + let seg = path.path.segments.last()?; if seg.ident != type_ { return None; } diff --git a/src/meta/src/barrier/progress.rs b/src/meta/src/barrier/progress.rs index 0c753a3c3f025..f22c5a2bbb216 100644 --- a/src/meta/src/barrier/progress.rs +++ b/src/meta/src/barrier/progress.rs @@ -38,7 +38,7 @@ type ConsumedRows = u64; #[derive(Clone, Copy, Debug)] enum BackfillState { Init, - ConsumingUpstream(Epoch, ConsumedRows), + ConsumingUpstream(#[allow(dead_code)] Epoch, ConsumedRows), Done(ConsumedRows), } diff --git a/src/meta/src/hummock/compaction/picker/manual_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/manual_compaction_picker.rs index 27a00b05ffcc4..f46a99bc80c0d 100644 --- a/src/meta/src/hummock/compaction/picker/manual_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/manual_compaction_picker.rs @@ -688,7 +688,7 @@ pub mod tests { // pick_l0_to_base_level let mut picker = ManualCompactionPicker::new(Arc::new(RangeOverlapStrategy::default()), option, 1); - let mut expected = vec![vec![5, 6], vec![7, 8], vec![9, 10]]; + let mut expected = [vec![5, 6], vec![7, 8], vec![9, 10]]; expected.reverse(); let result = picker .pick_compaction(&levels, &levels_handler, &mut local_stats) @@ -724,7 +724,7 @@ pub mod tests { }; let mut picker = ManualCompactionPicker::new(Arc::new(RangeOverlapStrategy::default()), option, 1); - let mut expected = vec![vec![5, 6], vec![7, 8]]; + let mut expected = [vec![5, 6], vec![7, 8]]; expected.reverse(); let result = picker .pick_compaction(&levels, &levels_handler, &mut local_stats) @@ -1012,7 +1012,7 @@ pub mod tests { } { - let expected_input_level_sst_ids = vec![vec![4], vec![2]]; + let expected_input_level_sst_ids = [vec![4], vec![2]]; let option = ManualCompactionOption { sst_ids: vec![], level: input_level, diff --git a/src/meta/src/hummock/compaction/picker/min_overlap_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/min_overlap_compaction_picker.rs index 8a76cc56f6b3c..e34963ab48f9f 100644 --- a/src/meta/src/hummock/compaction/picker/min_overlap_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/min_overlap_compaction_picker.rs @@ -874,7 +874,7 @@ pub mod tests { #[test] fn test_trivial_move_bug() { - let levels = vec![ + let levels = [ Level { level_idx: 1, level_type: LevelType::Nonoverlapping as i32, diff --git a/src/meta/src/hummock/compaction/picker/space_reclaim_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/space_reclaim_compaction_picker.rs index 506815dbed40a..5d05fedbe5338 100644 --- a/src/meta/src/hummock/compaction/picker/space_reclaim_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/space_reclaim_compaction_picker.rs @@ -409,7 +409,7 @@ mod test { // cut range [3,4] [6] [8,9,10] levels.member_table_ids = vec![0, 1, 2, 5, 7]; let expect_task_file_count = [2, 1, 4]; - let expect_task_sst_id_range = vec![vec![3, 4], vec![6], vec![8, 9, 10, 11]]; + let expect_task_sst_id_range = [vec![3, 4], vec![6], vec![8, 9, 10, 11]]; for (index, x) in expect_task_file_count.iter().enumerate() { // // pick space reclaim let task = selector @@ -460,7 +460,7 @@ mod test { // cut range [3,4] [6] [8,9,10] levels.member_table_ids = vec![0, 1, 2, 5, 7]; let expect_task_file_count = [2, 1, 5]; - let expect_task_sst_id_range = vec![vec![3, 4], vec![6], vec![7, 8, 9, 10, 11]]; + let expect_task_sst_id_range = [vec![3, 4], vec![6], vec![7, 8, 9, 10, 11]]; for (index, x) in expect_task_file_count.iter().enumerate() { if index == expect_task_file_count.len() - 1 { levels.member_table_ids = vec![2, 5]; diff --git a/src/meta/src/hummock/compaction/picker/ttl_reclaim_compaction_picker.rs b/src/meta/src/hummock/compaction/picker/ttl_reclaim_compaction_picker.rs index 307d8f2b0174e..f690b0f80112c 100644 --- a/src/meta/src/hummock/compaction/picker/ttl_reclaim_compaction_picker.rs +++ b/src/meta/src/hummock/compaction/picker/ttl_reclaim_compaction_picker.rs @@ -611,7 +611,7 @@ mod test { ); let expect_task_file_count = [1, 1, 1]; - let expect_task_sst_id_range = vec![vec![2], vec![3], vec![4]]; + let expect_task_sst_id_range = [vec![2], vec![3], vec![4]]; for (index, x) in expect_task_file_count.iter().enumerate() { // // pick ttl reclaim let task = selector @@ -694,7 +694,7 @@ mod test { ); let expect_task_file_count = [1, 1]; - let expect_task_sst_id_range = vec![vec![2], vec![3]]; + let expect_task_sst_id_range = [vec![2], vec![3]]; for (index, x) in expect_task_file_count.iter().enumerate() { if index == expect_task_file_count.len() - 1 { table_id_to_options.insert( diff --git a/src/meta/src/hummock/compaction/selector/level_selector.rs b/src/meta/src/hummock/compaction/selector/level_selector.rs index a24f88cbf0fc6..5c118269cfee3 100644 --- a/src/meta/src/hummock/compaction/selector/level_selector.rs +++ b/src/meta/src/hummock/compaction/selector/level_selector.rs @@ -50,14 +50,14 @@ pub enum PickerType { BottomLevel, } -impl ToString for PickerType { - fn to_string(&self) -> String { - match self { - PickerType::Tier => String::from("Tier"), - PickerType::Intra => String::from("Intra"), - PickerType::ToBase => String::from("ToBase"), - PickerType::BottomLevel => String::from("BottomLevel"), - } +impl std::fmt::Display for PickerType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + PickerType::Tier => "Tier", + PickerType::Intra => "Intra", + PickerType::ToBase => "ToBase", + PickerType::BottomLevel => "BottomLevel", + }) } } diff --git a/src/storage/benches/bench_fs_operation.rs b/src/storage/benches/bench_fs_operation.rs index 4f01af01e60cc..0983883fdaa44 100644 --- a/src/storage/benches/bench_fs_operation.rs +++ b/src/storage/benches/bench_fs_operation.rs @@ -94,6 +94,7 @@ fn gen_tokio_files(path: &Path) -> impl IntoIterator impl IntoIterator TestIngestBatch for S { } } +#[cfg(test)] #[async_trait::async_trait] pub(crate) trait HummockStateStoreTestTrait: StateStore { fn get_pinned_version(&self) -> PinnedVersion; @@ -120,6 +121,7 @@ pub(crate) trait HummockStateStoreTestTrait: StateStore { } } +#[cfg(test)] impl HummockStateStoreTestTrait for HummockStorage { fn get_pinned_version(&self) -> PinnedVersion { self.get_pinned_version() diff --git a/src/storage/hummock_trace/src/write.rs b/src/storage/hummock_trace/src/write.rs index 3038ffb9a7ee8..528cdac5f659d 100644 --- a/src/storage/hummock_trace/src/write.rs +++ b/src/storage/hummock_trace/src/write.rs @@ -30,13 +30,6 @@ pub(crate) static MAGIC_BYTES: MagicBytes = 0x484D5452; // HMTR pub(crate) trait TraceWriter { fn write(&mut self, record: Record) -> Result; fn flush(&mut self) -> Result<()>; - fn write_all(&mut self, records: Vec) -> Result { - let mut total_size = 0; - for r in records { - total_size += self.write(r)? - } - Ok(total_size) - } } /// Serializer serializes a record to std write. diff --git a/src/storage/src/hummock/block_cache.rs b/src/storage/src/hummock/block_cache.rs index e71714e8f8bb0..9023f045c0557 100644 --- a/src/storage/src/hummock/block_cache.rs +++ b/src/storage/src/hummock/block_cache.rs @@ -34,9 +34,9 @@ const MIN_BUFFER_SIZE_PER_SHARD: usize = 256 * 1024 * 1024; type CachedBlockEntry = CacheableEntry<(HummockSstableObjectId, u64), Box>; enum BlockEntry { - Cache(CachedBlockEntry), - Owned(Box), - RefEntry(Arc), + Cache(#[allow(dead_code)] CachedBlockEntry), + Owned(#[allow(dead_code)] Box), + RefEntry(#[allow(dead_code)] Arc), } pub struct BlockHolder { diff --git a/src/stream/src/common/table/state_table_cache.rs b/src/stream/src/common/table/state_table_cache.rs index 06acd7e710dce..8c8014548a1e1 100644 --- a/src/stream/src/common/table/state_table_cache.rs +++ b/src/stream/src/common/table/state_table_cache.rs @@ -453,23 +453,23 @@ mod tests { #[test] fn test_watermark_cache_syncing() { - let v1 = vec![ + let v1 = [ Some(Timestamptz::from_secs(1000).unwrap().to_scalar_value()), Some(1000i64.into()), ]; - let v2 = vec![ + let v2 = [ Some(Timestamptz::from_secs(3000).unwrap().to_scalar_value()), Some(1000i64.into()), ]; - let v3 = vec![ + let v3 = [ Some(Timestamptz::from_secs(2000).unwrap().to_scalar_value()), Some(1000i64.into()), ]; let mut cache = StateTableWatermarkCache::new(3); let mut filler = cache.begin_syncing(); - filler.insert_unchecked(DefaultOrdered(v1.into_owned_row()), ()); - filler.insert_unchecked(DefaultOrdered(v2.into_owned_row()), ()); - filler.insert_unchecked(DefaultOrdered(v3.into_owned_row()), ()); + filler.insert_unchecked(DefaultOrdered(v1.to_owned_row()), ()); + filler.insert_unchecked(DefaultOrdered(v2.to_owned_row()), ()); + filler.insert_unchecked(DefaultOrdered(v3.to_owned_row()), ()); filler.finish(); assert_eq!(cache.len(), 3); assert_eq!( diff --git a/src/stream/src/executor/top_n/top_n_plain.rs b/src/stream/src/executor/top_n/top_n_plain.rs index 8536d9d3273c3..5df41cfca3a05 100644 --- a/src/stream/src/executor/top_n/top_n_plain.rs +++ b/src/stream/src/executor/top_n/top_n_plain.rs @@ -761,7 +761,7 @@ mod tests { } fn create_source_new_before_recovery() -> Box { - let mut chunks = vec![ + let mut chunks = [ StreamChunk::from_pretty( " I I I I + 1 1 4 1001", @@ -792,7 +792,7 @@ mod tests { } fn create_source_new_after_recovery() -> Box { - let mut chunks = vec![ + let mut chunks = [ StreamChunk::from_pretty( " I I I I + 1 9 1 1003 @@ -1209,7 +1209,7 @@ mod tests { } fn create_source_before_recovery() -> Box { - let mut chunks = vec![ + let mut chunks = [ StreamChunk::from_pretty( " I I + 1 0 @@ -1248,7 +1248,7 @@ mod tests { } fn create_source_after_recovery() -> Box { - let mut chunks = vec![ + let mut chunks = [ StreamChunk::from_pretty( " I I - 1 0", diff --git a/src/stream/src/executor/top_n/top_n_state.rs b/src/stream/src/executor/top_n/top_n_state.rs index a979aeb629955..f8dbbcabe00d4 100644 --- a/src/stream/src/executor/top_n/top_n_state.rs +++ b/src/stream/src/executor/top_n/top_n_state.rs @@ -364,8 +364,8 @@ mod tests { let row2_bytes = serialize_pk_to_cache_key(row2.clone(), &cache_key_serde); let row3_bytes = serialize_pk_to_cache_key(row3.clone(), &cache_key_serde); let row4_bytes = serialize_pk_to_cache_key(row4.clone(), &cache_key_serde); - let rows = vec![row1, row2, row3, row4]; - let ordered_rows = vec![row1_bytes, row2_bytes, row3_bytes, row4_bytes]; + let rows = [row1, row2, row3, row4]; + let ordered_rows = [row1_bytes, row2_bytes, row3_bytes, row4_bytes]; managed_state.insert(rows[3].clone()); // now ("ab", 4) @@ -446,7 +446,7 @@ mod tests { let row3_bytes = serialize_pk_to_cache_key(row3.clone(), &cache_key_serde); let row4_bytes = serialize_pk_to_cache_key(row4.clone(), &cache_key_serde); let row5_bytes = serialize_pk_to_cache_key(row5.clone(), &cache_key_serde); - let rows = vec![row1, row2, row3, row4, row5]; + let rows = [row1, row2, row3, row4, row5]; let ordered_rows = vec![row1_bytes, row2_bytes, row3_bytes, row4_bytes, row5_bytes]; let mut cache = TopNCache::::new(1, 1, data_types); diff --git a/src/utils/pgwire/src/pg_server.rs b/src/utils/pgwire/src/pg_server.rs index 9425781f54005..e545c8a2d724e 100644 --- a/src/utils/pgwire/src/pg_server.rs +++ b/src/utils/pgwire/src/pg_server.rs @@ -130,7 +130,7 @@ pub struct ExecContext { /// `ExecContextGuard` holds a `Arc` pointer. Once `ExecContextGuard` is dropped, /// the inner `Arc` should not be referred anymore, so that its `Weak` reference (used in `SessionImpl`) will be the same lifecycle of the running sql execution context. -pub struct ExecContextGuard(Arc); +pub struct ExecContextGuard(#[allow(dead_code)] Arc); impl ExecContextGuard { pub fn new(exec_context: Arc) -> Self {