From 2e3d052c54e6e4b32954141f0be27a05e0614c98 Mon Sep 17 00:00:00 2001 From: sigaloid <69441971+sigaloid@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:57:35 -0400 Subject: [PATCH 1/4] cargo +nightly clippy --fix -Z unstable-options --- src/core/index.rs | 2 +- src/functional_test.rs | 2 +- src/indexer/merger.rs | 5 ++--- src/indexer/merger_sorted_index_test.rs | 9 +++------ src/postings/block_segment_postings.rs | 2 +- src/schema/mod.rs | 2 +- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/core/index.rs b/src/core/index.rs index b5b04dcf2a..4ad143219a 100644 --- a/src/core/index.rs +++ b/src/core/index.rs @@ -535,7 +535,7 @@ impl Index { let mut damaged_files = HashSet::new(); for path in active_existing_files { - if !self.directory.validate_checksum(&path)? { + if !self.directory.validate_checksum(path)? { damaged_files.insert((*path).clone()); } } diff --git a/src/functional_test.rs b/src/functional_test.rs index f76e42e7bc..a719033413 100644 --- a/src/functional_test.rs +++ b/src/functional_test.rs @@ -141,7 +141,7 @@ const LOREM: &str = "Doc Lorem ipsum dolor sit amet, consectetur adipiscing elit fn get_text() -> String { use rand::seq::SliceRandom; let mut rng = thread_rng(); - let tokens: Vec<_> = LOREM.split(" ").collect(); + let tokens: Vec<_> = LOREM.split(' ').collect(); let random_val = rng.gen_range(0..20); (0..random_val) diff --git a/src/indexer/merger.rs b/src/indexer/merger.rs index 8d07506ccb..537d36905f 100644 --- a/src/indexer/merger.rs +++ b/src/indexer/merger.rs @@ -149,8 +149,7 @@ impl TermOrdinalMapping { self.per_segment_new_term_ordinals .iter() .flat_map(|term_ordinals| term_ordinals.iter().cloned().max()) - .max() - .unwrap_or_else(TermOrdinal::default) + .max().unwrap_or_default() } } @@ -966,7 +965,7 @@ impl IndexMerger { doc_id_and_positions.sort_unstable_by_key(|&(doc_id, _, _)| doc_id); for (doc_id, term_freq, positions) in &doc_id_and_positions { - let delta_positions = delta_computer.compute_delta(&positions); + let delta_positions = delta_computer.compute_delta(positions); field_serializer.write_doc(*doc_id, *term_freq, delta_positions); } doc_id_and_positions.clear(); diff --git a/src/indexer/merger_sorted_index_test.rs b/src/indexer/merger_sorted_index_test.rs index 629823f5f0..579a5c6404 100644 --- a/src/indexer/merger_sorted_index_test.rs +++ b/src/indexer/merger_sorted_index_test.rs @@ -261,8 +261,7 @@ mod tests { assert_eq!( postings.doc_freq_given_deletes( segment_reader - .delete_bitset() - .unwrap_or_else(|| &&fallback_bitset) + .delete_bitset().unwrap_or(&fallback_bitset) ), 2 ); @@ -342,8 +341,7 @@ mod tests { assert_eq!( postings.doc_freq_given_deletes( segment_reader - .delete_bitset() - .unwrap_or_else(|| &&fallback_bitset) + .delete_bitset().unwrap_or(&fallback_bitset) ), 2 ); @@ -454,8 +452,7 @@ mod tests { assert_eq!( postings.doc_freq_given_deletes( segment_reader - .delete_bitset() - .unwrap_or_else(|| &&fallback_bitset) + .delete_bitset().unwrap_or(&fallback_bitset) ), 2 ); diff --git a/src/postings/block_segment_postings.rs b/src/postings/block_segment_postings.rs index d12e8e994d..941d3f6b7b 100644 --- a/src/postings/block_segment_postings.rs +++ b/src/postings/block_segment_postings.rs @@ -209,7 +209,7 @@ impl BlockSegmentPostings { #[inline] pub(crate) fn full_block(&self) -> &[DocId; COMPRESSION_BLOCK_SIZE] { debug_assert!(self.block_is_loaded()); - &self.doc_decoder.full_output() + self.doc_decoder.full_output() } /// Return the document at index `idx` of the block. diff --git a/src/schema/mod.rs b/src/schema/mod.rs index bed26a295f..b1ea12e273 100644 --- a/src/schema/mod.rs +++ b/src/schema/mod.rs @@ -157,7 +157,7 @@ pub use self::int_options::IntOptions; /// A field name can be any character, must have at least one character /// and must not start with a `-`. pub fn is_valid_field_name(field_name: &str) -> bool { - field_name.len() > 0 && !field_name.starts_with('-') + !field_name.is_empty() && !field_name.starts_with('-') } #[cfg(test)] From 7e0fe20adab622228b1e1a7f2cfde5ed2611f8ad Mon Sep 17 00:00:00 2001 From: sigaloid <69441971+sigaloid@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:57:50 -0400 Subject: [PATCH 2/4] cargo fmt (again) --- src/indexer/merger.rs | 3 ++- src/indexer/merger_sorted_index_test.rs | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/indexer/merger.rs b/src/indexer/merger.rs index 537d36905f..295a5fde66 100644 --- a/src/indexer/merger.rs +++ b/src/indexer/merger.rs @@ -149,7 +149,8 @@ impl TermOrdinalMapping { self.per_segment_new_term_ordinals .iter() .flat_map(|term_ordinals| term_ordinals.iter().cloned().max()) - .max().unwrap_or_default() + .max() + .unwrap_or_default() } } diff --git a/src/indexer/merger_sorted_index_test.rs b/src/indexer/merger_sorted_index_test.rs index 579a5c6404..d06f0b40d4 100644 --- a/src/indexer/merger_sorted_index_test.rs +++ b/src/indexer/merger_sorted_index_test.rs @@ -260,8 +260,7 @@ mod tests { let fallback_bitset = DeleteBitSet::for_test(&[0], 100); assert_eq!( postings.doc_freq_given_deletes( - segment_reader - .delete_bitset().unwrap_or(&fallback_bitset) + segment_reader.delete_bitset().unwrap_or(&fallback_bitset) ), 2 ); @@ -340,8 +339,7 @@ mod tests { let fallback_bitset = DeleteBitSet::for_test(&[0], 100); assert_eq!( postings.doc_freq_given_deletes( - segment_reader - .delete_bitset().unwrap_or(&fallback_bitset) + segment_reader.delete_bitset().unwrap_or(&fallback_bitset) ), 2 ); @@ -451,8 +449,7 @@ mod tests { let fallback_bitset = DeleteBitSet::for_test(&[0], 100); assert_eq!( postings.doc_freq_given_deletes( - segment_reader - .delete_bitset().unwrap_or(&fallback_bitset) + segment_reader.delete_bitset().unwrap_or(&fallback_bitset) ), 2 ); From 707970c49ed05f3b31dc915ec1fa263702fe092a Mon Sep 17 00:00:00 2001 From: sigaloid <69441971+sigaloid@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:05:55 -0400 Subject: [PATCH 3/4] clippy suggestions (ignoring f32->f64 comparison, not sure what margin should be) --- examples/custom_collector.rs | 10 ++++------ src/fastfield/serializer/mod.rs | 2 +- src/postings/serializer.rs | 6 ++---- src/query/automaton_weight.rs | 5 +---- src/query/boolean_query/mod.rs | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/examples/custom_collector.rs b/examples/custom_collector.rs index 9abf5fc44e..2b84d2cc20 100644 --- a/examples/custom_collector.rs +++ b/examples/custom_collector.rs @@ -86,12 +86,10 @@ impl Collector for StatsCollector { fn merge_fruits(&self, segment_stats: Vec>) -> tantivy::Result> { let mut stats = Stats::default(); - for segment_stats_opt in segment_stats { - if let Some(segment_stats) = segment_stats_opt { - stats.count += segment_stats.count; - stats.sum += segment_stats.sum; - stats.squared_sum += segment_stats.squared_sum; - } + for segment_stats in segment_stats.into_iter().flatten() { + stats.count += segment_stats.count; + stats.sum += segment_stats.sum; + stats.squared_sum += segment_stats.squared_sum; } Ok(stats.non_zero_count()) } diff --git a/src/fastfield/serializer/mod.rs b/src/fastfield/serializer/mod.rs index 7d8ea8fe54..9778adc798 100644 --- a/src/fastfield/serializer/mod.rs +++ b/src/fastfield/serializer/mod.rs @@ -107,7 +107,7 @@ impl CompositeFastFieldSerializer { ); if let Some(broken_estimation) = estimations .iter() - .find(|estimation| estimation.0 == f32::NAN) + .find(|estimation| estimation.0.is_nan()) { warn!( "broken estimation for fast field codec {}", diff --git a/src/postings/serializer.rs b/src/postings/serializer.rs index 40e3ca2acc..99e1241a96 100644 --- a/src/postings/serializer.rs +++ b/src/postings/serializer.rs @@ -443,10 +443,8 @@ impl PostingsSerializer { let skip_data = self.skip_write.data(); VInt(skip_data.len() as u64).serialize(&mut self.output_write)?; self.output_write.write_all(skip_data)?; - self.output_write.write_all(&self.postings_write[..])?; - } else { - self.output_write.write_all(&self.postings_write[..])?; - } + } + self.output_write.write_all(&self.postings_write[..])?; self.skip_write.clear(); self.postings_write.clear(); self.bm25_weight = None; diff --git a/src/query/automaton_weight.rs b/src/query/automaton_weight.rs index ae9bbc45ea..b2185ada83 100644 --- a/src/query/automaton_weight.rs +++ b/src/query/automaton_weight.rs @@ -121,10 +121,7 @@ mod tests { } fn is_match(&self, state: &Self::State) -> bool { - match *state { - State::AfterA => true, - _ => false, - } + matches!(*state, State::AfterA) } fn accept(&self, state: &Self::State, byte: u8) -> Self::State { diff --git a/src/query/boolean_query/mod.rs b/src/query/boolean_query/mod.rs index 3697f2fde5..c2d80ae426 100644 --- a/src/query/boolean_query/mod.rs +++ b/src/query/boolean_query/mod.rs @@ -310,7 +310,7 @@ mod tests { )); let query = BooleanQuery::from(vec![(Occur::Should, term_a), (Occur::Should, term_b)]); let explanation = query.explain(&searcher, DocAddress::new(0, 0u32))?; - assert_nearly_equals!(explanation.value(), 0.6931472); + assert_nearly_equals!(explanation.value(), std::f32::consts::LN_2); Ok(()) } } From 047afcc4a247f5f75e41ba954ec419f48bc518c6 Mon Sep 17 00:00:00 2001 From: sigaloid <69441971+sigaloid@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:06:11 -0400 Subject: [PATCH 4/4] Cargo fmt --- src/fastfield/serializer/mod.rs | 4 +--- src/postings/serializer.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/fastfield/serializer/mod.rs b/src/fastfield/serializer/mod.rs index 9778adc798..e9009ec499 100644 --- a/src/fastfield/serializer/mod.rs +++ b/src/fastfield/serializer/mod.rs @@ -105,9 +105,7 @@ impl CompositeFastFieldSerializer { &fastfield_accessor, &mut estimations, ); - if let Some(broken_estimation) = estimations - .iter() - .find(|estimation| estimation.0.is_nan()) + if let Some(broken_estimation) = estimations.iter().find(|estimation| estimation.0.is_nan()) { warn!( "broken estimation for fast field codec {}", diff --git a/src/postings/serializer.rs b/src/postings/serializer.rs index 99e1241a96..f36c896e8c 100644 --- a/src/postings/serializer.rs +++ b/src/postings/serializer.rs @@ -443,7 +443,7 @@ impl PostingsSerializer { let skip_data = self.skip_write.data(); VInt(skip_data.len() as u64).serialize(&mut self.output_write)?; self.output_write.write_all(skip_data)?; - } + } self.output_write.write_all(&self.postings_write[..])?; self.skip_write.clear(); self.postings_write.clear();