diff --git a/filter-parser/src/lib.rs b/filter-parser/src/lib.rs index 9a3e0f1f8..c595cf827 100644 --- a/filter-parser/src/lib.rs +++ b/filter-parser/src/lib.rs @@ -401,7 +401,7 @@ pub mod tests { fn parse() { use FilterCondition as Fc; - fn p<'a>(s: &'a str) -> impl std::fmt::Display + 'a { + fn p(s: &str) -> impl std::fmt::Display + '_ { Fc::parse(s).unwrap().unwrap() } @@ -494,7 +494,7 @@ pub mod tests { fn error() { use FilterCondition as Fc; - fn p<'a>(s: &'a str) -> impl std::fmt::Display + 'a { + fn p(s: &str) -> impl std::fmt::Display + '_ { Fc::parse(s).unwrap_err().to_string() } diff --git a/milli/src/heed_codec/facet/mod.rs b/milli/src/heed_codec/facet/mod.rs index 4609bfe7f..d36ec8434 100644 --- a/milli/src/heed_codec/facet/mod.rs +++ b/milli/src/heed_codec/facet/mod.rs @@ -88,8 +88,7 @@ impl<'a> heed::BytesEncode<'a> for FacetGroupValueCodec { type EItem = FacetGroupValue; fn bytes_encode(value: &'a Self::EItem) -> Option> { - let mut v = vec![]; - v.push(value.size); + let mut v = vec![value.size]; CboRoaringBitmapCodec::serialize_into(&value.bitmap, &mut v); Some(Cow::Owned(v)) } diff --git a/milli/src/search/facet/facet_distribution_iter.rs b/milli/src/search/facet/facet_distribution_iter.rs index 9cd85b667..6e209c7aa 100644 --- a/milli/src/search/facet/facet_distribution_iter.rs +++ b/milli/src/search/facet/facet_distribution_iter.rs @@ -38,9 +38,9 @@ where if let Some(first_bound) = get_first_facet_value::(rtxn, db, field_id)? { fd.iterate(candidates, highest_level, first_bound, usize::MAX)?; - return Ok(()); + Ok(()) } else { - return Ok(()); + Ok(()) } } @@ -84,7 +84,7 @@ where } } } - return Ok(ControlFlow::Continue(())); + Ok(ControlFlow::Continue(())) } fn iterate( &mut self, @@ -98,7 +98,7 @@ where } let starting_key = FacetGroupKey { field_id: self.field_id, level, left_bound: starting_bound }; - let iter = self.db.range(&self.rtxn, &(&starting_key..)).unwrap().take(group_size); + let iter = self.db.range(self.rtxn, &(&starting_key..)).unwrap().take(group_size); for el in iter { let (key, value) = el.unwrap(); @@ -108,7 +108,7 @@ where return Ok(ControlFlow::Break(())); } let docids_in_common = value.bitmap & candidates; - if docids_in_common.len() > 0 { + if !docids_in_common.is_empty() { let cf = self.iterate( &docids_in_common, level - 1, @@ -121,8 +121,7 @@ where } } } - - return Ok(ControlFlow::Continue(())); + Ok(ControlFlow::Continue(())) } } diff --git a/milli/src/search/facet/facet_range_search.rs b/milli/src/search/facet/facet_range_search.rs index 07300e920..e8eeab1cc 100644 --- a/milli/src/search/facet/facet_range_search.rs +++ b/milli/src/search/facet/facet_range_search.rs @@ -60,7 +60,7 @@ where f.run(highest_level, starting_left_bound, rightmost_bound, group_size)?; Ok(()) } else { - return Ok(()); + Ok(()) } } @@ -77,7 +77,7 @@ impl<'t, 'b, 'bitmap> FacetRangeSearch<'t, 'b, 'bitmap> { fn run_level_0(&mut self, starting_left_bound: &'t [u8], group_size: usize) -> Result<()> { let left_key = FacetGroupKey { field_id: self.field_id, level: 0, left_bound: starting_left_bound }; - let iter = self.db.range(&self.rtxn, &(left_key..))?.take(group_size); + let iter = self.db.range(self.rtxn, &(left_key..))?.take(group_size); for el in iter { let (key, value) = el?; // the right side of the iter range is unbounded, so we need to make sure that we are not iterating @@ -145,7 +145,7 @@ impl<'t, 'b, 'bitmap> FacetRangeSearch<'t, 'b, 'bitmap> { let left_key = FacetGroupKey { field_id: self.field_id, level, left_bound: starting_left_bound }; - let mut iter = self.db.range(&self.rtxn, &(left_key..))?.take(group_size); + let mut iter = self.db.range(self.rtxn, &(left_key..))?.take(group_size); // We iterate over the range while keeping in memory the previous value let (mut previous_key, mut previous_value) = iter.next().unwrap()?; @@ -348,6 +348,7 @@ mod tests { &mut docids, ) .unwrap(); + #[allow(clippy::format_push_string)] results.push_str(&format!("{}\n", display_bitmap(&docids))); } milli_snap!(results, format!("included_{i}")); @@ -366,6 +367,7 @@ mod tests { &mut docids, ) .unwrap(); + #[allow(clippy::format_push_string)] results.push_str(&format!("{}\n", display_bitmap(&docids))); } milli_snap!(results, format!("excluded_{i}")); diff --git a/milli/src/search/facet/facet_sort_ascending.rs b/milli/src/search/facet/facet_sort_ascending.rs index 2f1f73db3..552795981 100644 --- a/milli/src/search/facet/facet_sort_ascending.rs +++ b/milli/src/search/facet/facet_sort_ascending.rs @@ -50,6 +50,7 @@ struct AscendingFacetSort<'t, 'e> { rtxn: &'t heed::RoTxn<'e>, db: heed::Database, FacetGroupValueCodec>, field_id: u16, + #[allow(clippy::type_complexity)] stack: Vec<( RoaringBitmap, std::iter::Take< @@ -91,9 +92,9 @@ impl<'t, 'e> Iterator for AscendingFacetSort<'t, 'e> { } let starting_key_below = FacetGroupKey { field_id: self.field_id, level: level - 1, left_bound }; - let iter = match self.db.range(&self.rtxn, &(starting_key_below..)) { + let iter = match self.db.range(self.rtxn, &(starting_key_below..)) { Ok(iter) => iter, - Err(e) => return Some(Err(e.into())), + Err(e) => return Some(Err(e)), } .take(group_size as usize); diff --git a/milli/src/search/facet/facet_sort_descending.rs b/milli/src/search/facet/facet_sort_descending.rs index 5f09d708b..6f073b62a 100644 --- a/milli/src/search/facet/facet_sort_descending.rs +++ b/milli/src/search/facet/facet_sort_descending.rs @@ -39,6 +39,7 @@ struct DescendingFacetSort<'t> { rtxn: &'t heed::RoTxn<'t>, db: heed::Database, FacetGroupValueCodec>, field_id: u16, + #[allow(clippy::type_complexity)] stack: Vec<( RoaringBitmap, std::iter::Take< @@ -54,7 +55,7 @@ impl<'t> Iterator for DescendingFacetSort<'t> { fn next(&mut self) -> Option { 'outer: loop { let (documents_ids, deepest_iter, right_bound) = self.stack.last_mut()?; - while let Some(result) = deepest_iter.next() { + for result in deepest_iter.by_ref() { let ( FacetGroupKey { level, left_bound, field_id }, FacetGroupValue { size: group_size, mut bitmap }, @@ -100,11 +101,11 @@ impl<'t> Iterator for DescendingFacetSort<'t> { .db .remap_key_type::>() .rev_range( - &self.rtxn, + self.rtxn, &(Bound::Included(starting_key_below), end_key_kelow), ) { Ok(iter) => iter, - Err(e) => return Some(Err(e.into())), + Err(e) => return Some(Err(e)), } .take(group_size as usize); diff --git a/milli/src/search/facet/mod.rs b/milli/src/search/facet/mod.rs index ccf40d6aa..7dfdcdb94 100644 --- a/milli/src/search/facet/mod.rs +++ b/milli/src/search/facet/mod.rs @@ -73,7 +73,7 @@ pub(crate) fn get_highest_level<'t>( let field_id_prefix = &field_id.to_be_bytes(); Ok(db .as_polymorph() - .rev_prefix_iter::<_, ByteSlice, DecodeIgnore>(&txn, field_id_prefix)? + .rev_prefix_iter::<_, ByteSlice, DecodeIgnore>(txn, field_id_prefix)? .next() .map(|el| { let (key, _) = el.unwrap(); @@ -105,12 +105,9 @@ pub(crate) mod tests { pub fn get_random_looking_index() -> FacetIndex { let index = FacetIndex::::new(4, 8, 5); let mut txn = index.env.write_txn().unwrap(); - let mut rng = rand::rngs::SmallRng::from_seed([0; 32]); - let keys = - std::iter::from_fn(|| Some(rng.gen_range(0..256))).take(128).collect::>(); - for (_i, key) in keys.into_iter().enumerate() { + for (_i, key) in std::iter::from_fn(|| Some(rng.gen_range(0..256))).take(128).enumerate() { let mut bitmap = RoaringBitmap::new(); bitmap.insert(key); bitmap.insert(key + 100); diff --git a/milli/src/update/delete_documents.rs b/milli/src/update/delete_documents.rs index 1dd3f423b..a6a4ea609 100644 --- a/milli/src/update/delete_documents.rs +++ b/milli/src/update/delete_documents.rs @@ -138,7 +138,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { // the `soft_deleted_documents_ids` bitmap and early exit. let size_used = self.index.used_size()?; let map_size = self.index.env.map_size()? as u64; - let nb_documents = self.index.number_of_documents(&self.wtxn)?; + let nb_documents = self.index.number_of_documents(self.wtxn)?; let nb_soft_deleted = soft_deleted_docids.len(); let percentage_available = 100 - (size_used * 100 / map_size); @@ -474,7 +474,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { self.index.put_faceted_documents_ids(self.wtxn, field_id, facet_type, &docids)?; let facet_values = remove_docids_from_field_id_docid_facet_value( - &self.index, + self.index, self.wtxn, facet_type, field_id, diff --git a/milli/src/update/facet/bulk.rs b/milli/src/update/facet/bulk.rs index ea0a7d3d7..2a4c7f49a 100644 --- a/milli/src/update/facet/bulk.rs +++ b/milli/src/update/facet/bulk.rs @@ -111,7 +111,7 @@ impl FacetsUpdateBulkInner { } for &field_id in field_ids.iter() { - let (level_readers, all_docids) = self.compute_levels_for_field_id(field_id, &wtxn)?; + let (level_readers, all_docids) = self.compute_levels_for_field_id(field_id, wtxn)?; handle_all_docids(wtxn, field_id, all_docids)?; @@ -341,7 +341,7 @@ impl FacetsUpdateBulkInner { handle_group(&bitmaps, left_bounds.first().unwrap())?; } } - return Ok(sub_writers); + Ok(sub_writers) } } diff --git a/milli/src/update/facet/delete.rs b/milli/src/update/facet/delete.rs index 2bc54c7c1..9bec2d911 100644 --- a/milli/src/update/facet/delete.rs +++ b/milli/src/update/facet/delete.rs @@ -100,7 +100,7 @@ impl<'i, 'b> FacetsDelete<'i, 'b> { max_group_size: self.max_group_size, }; for facet_value in affected_facet_values { - inc.delete(wtxn, field_id, facet_value.as_slice(), &self.docids_to_delete)?; + inc.delete(wtxn, field_id, facet_value.as_slice(), self.docids_to_delete)?; } } } diff --git a/milli/src/update/facet/incremental.rs b/milli/src/update/facet/incremental.rs index 2558c81a3..04d702987 100644 --- a/milli/src/update/facet/incremental.rs +++ b/milli/src/update/facet/incremental.rs @@ -127,7 +127,7 @@ impl FacetsUpdateIncrementalInner { if let Some(e) = prefix_iter.next() { let (key_bytes, value) = e?; Ok(( - FacetGroupKeyCodec::::bytes_decode(&key_bytes) + FacetGroupKeyCodec::::bytes_decode(key_bytes) .ok_or(Error::Encoding)? .into_owned(), value, @@ -146,11 +146,11 @@ impl FacetsUpdateIncrementalInner { .as_polymorph() .prefix_iter::<_, ByteSlice, FacetGroupValueCodec>( txn, - &prefix.as_slice(), + prefix.as_slice(), )?; let (key_bytes, value) = iter.next().unwrap()?; Ok(( - FacetGroupKeyCodec::::bytes_decode(&key_bytes) + FacetGroupKeyCodec::::bytes_decode(key_bytes) .ok_or(Error::Encoding)? .into_owned(), value, @@ -185,15 +185,15 @@ impl FacetsUpdateIncrementalInner { let mut iter = self .db .as_polymorph() - .prefix_iter::<_, ByteSlice, DecodeIgnore>(&txn, &level0_prefix)?; + .prefix_iter::<_, ByteSlice, DecodeIgnore>(txn, &level0_prefix)?; if iter.next().is_none() { drop(iter); self.db.put(txn, &key, &value)?; - return Ok(InsertionResult::Insert); + Ok(InsertionResult::Insert) } else { drop(iter); - let old_value = self.db.get(&txn, &key)?; + let old_value = self.db.get(txn, &key)?; match old_value { Some(mut updated_value) => { // now merge the two @@ -236,7 +236,7 @@ impl FacetsUpdateIncrementalInner { let max_group_size = self.max_group_size; - let result = self.insert_in_level(txn, field_id, level - 1, facet_value.clone(), docids)?; + let result = self.insert_in_level(txn, field_id, level - 1, &(*facet_value), docids)?; // level below inserted an element let (insertion_key, insertion_value) = @@ -312,13 +312,13 @@ impl FacetsUpdateIncrementalInner { }; let mut iter = - self.db.range(&txn, &(start_key..))?.take((size_left as usize) + (size_right as usize)); + self.db.range(txn, &(start_key..))?.take((size_left as usize) + (size_right as usize)); let group_left = { let mut values_left = RoaringBitmap::new(); let mut i = 0; - while let Some(next) = iter.next() { + for next in iter.by_ref() { let (_key, value) = next?; i += 1; values_left |= &value.bitmap; @@ -339,7 +339,7 @@ impl FacetsUpdateIncrementalInner { FacetGroupValue { bitmap: mut values_right, .. }, ) = iter.next().unwrap()?; - while let Some(next) = iter.next() { + for next in iter.by_ref() { let (_, value) = next?; values_right |= &value.bitmap; } @@ -359,7 +359,7 @@ impl FacetsUpdateIncrementalInner { } /// Insert the given facet value and corresponding document ids in the database. - pub fn insert<'a, 't>( + pub fn insert<'t>( &self, txn: &'t mut RwTxn, field_id: u16, @@ -371,7 +371,7 @@ impl FacetsUpdateIncrementalInner { } let group_size = self.group_size; - let highest_level = get_highest_level(&txn, self.db, field_id)?; + let highest_level = get_highest_level(txn, self.db, field_id)?; let result = self.insert_in_level(txn, field_id, highest_level as u8, facet_value, docids)?; @@ -391,7 +391,7 @@ impl FacetsUpdateIncrementalInner { let size_highest_level = self .db .as_polymorph() - .prefix_iter::<_, ByteSlice, ByteSlice>(&txn, &highest_level_prefix)? + .prefix_iter::<_, ByteSlice, ByteSlice>(txn, &highest_level_prefix)? .count(); if size_highest_level < self.group_size as usize * self.min_level_size as usize { @@ -401,7 +401,7 @@ impl FacetsUpdateIncrementalInner { let mut groups_iter = self .db .as_polymorph() - .prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(&txn, &highest_level_prefix)?; + .prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(txn, &highest_level_prefix)?; let nbr_new_groups = size_highest_level / self.group_size as usize; let nbr_leftover_elements = size_highest_level % self.group_size as usize; @@ -412,7 +412,7 @@ impl FacetsUpdateIncrementalInner { let mut values = RoaringBitmap::new(); for _ in 0..group_size { let (key_bytes, value_i) = groups_iter.next().unwrap()?; - let key_i = FacetGroupKeyCodec::::bytes_decode(&key_bytes) + let key_i = FacetGroupKeyCodec::::bytes_decode(key_bytes) .ok_or(Error::Encoding)?; if first_key.is_none() { @@ -435,7 +435,7 @@ impl FacetsUpdateIncrementalInner { let mut values = RoaringBitmap::new(); for _ in 0..nbr_leftover_elements { let (key_bytes, value_i) = groups_iter.next().unwrap()?; - let key_i = FacetGroupKeyCodec::::bytes_decode(&key_bytes) + let key_i = FacetGroupKeyCodec::::bytes_decode(key_bytes) .ok_or(Error::Encoding)?; if first_key.is_none() { @@ -494,7 +494,7 @@ impl FacetsUpdateIncrementalInner { let (deletion_key, mut bitmap) = self.find_insertion_key_value(field_id, level, facet_value, txn)?; - let result = self.delete_in_level(txn, field_id, level - 1, facet_value.clone(), docids)?; + let result = self.delete_in_level(txn, field_id, level - 1, &(*facet_value), docids)?; let mut decrease_size = false; let next_key = match result { @@ -547,13 +547,13 @@ impl FacetsUpdateIncrementalInner { docids: &RoaringBitmap, ) -> Result { let key = FacetGroupKey { field_id, level: 0, left_bound: facet_value }; - let mut bitmap = self.db.get(&txn, &key)?.unwrap().bitmap; + let mut bitmap = self.db.get(txn, &key)?.unwrap().bitmap; bitmap -= docids; if bitmap.is_empty() { let mut next_key = None; if let Some((next, _)) = - self.db.remap_data_type::().get_greater_than(&txn, &key)? + self.db.remap_data_type::().get_greater_than(txn, &key)? { if next.field_id == field_id && next.level == 0 { next_key = Some(next.left_bound.to_vec()); @@ -567,7 +567,7 @@ impl FacetsUpdateIncrementalInner { } } - pub fn delete<'a, 't>( + pub fn delete<'t>( &self, txn: &'t mut RwTxn, field_id: u16, @@ -582,7 +582,7 @@ impl FacetsUpdateIncrementalInner { { return Ok(()); } - let highest_level = get_highest_level(&txn, self.db, field_id)?; + let highest_level = get_highest_level(txn, self.db, field_id)?; let result = self.delete_in_level(txn, field_id, highest_level as u8, facet_value, docids)?; @@ -603,7 +603,7 @@ impl FacetsUpdateIncrementalInner { || self .db .as_polymorph() - .prefix_iter::<_, ByteSlice, ByteSlice>(&txn, &highest_level_prefix)? + .prefix_iter::<_, ByteSlice, ByteSlice>(txn, &highest_level_prefix)? .count() >= self.min_level_size as usize { @@ -614,7 +614,7 @@ impl FacetsUpdateIncrementalInner { .db .as_polymorph() .prefix_iter::<_, ByteSlice, ByteSlice>(txn, &highest_level_prefix)?; - while let Some(el) = iter.next() { + for el in iter.by_ref() { let (k, _) = el?; to_delete.push( FacetGroupKeyCodec::::bytes_decode(k) @@ -640,7 +640,7 @@ impl<'a> FacetGroupKey<&'a [u8]> { } } -impl<'a> FacetGroupKey> { +impl FacetGroupKey> { pub fn as_ref(&self) -> FacetGroupKey<&[u8]> { FacetGroupKey { field_id: self.field_id, @@ -804,7 +804,7 @@ mod tests { let mut bitmap = RoaringBitmap::new(); bitmap.insert(i); index.verify_structure_validity(&txn, 0); - index.insert(&mut txn, 0, &(&(i as f64)), &bitmap); + index.insert(&mut txn, 0, &(i as f64), &bitmap); } for i in (200..256).into_iter().rev() {