659: Fix clippy error to add clippy job on Ci r=Kerollmops a=unvalley

## Related PR
This PR is for #673 

## What does this PR do?
- ~~add `Run Clippy` job to CI (rust.yml)~~
- apply `cargo clippy --fix` command
- fix some `cargo clippy` error manually (but warnings still remain on tests)

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?


Co-authored-by: unvalley <kirohi.code@gmail.com>
Co-authored-by: unvalley <38400669+unvalley@users.noreply.github.com>
This commit is contained in:
bors[bot]
2022-11-03 15:24:38 +00:00
committed by GitHub
31 changed files with 108 additions and 105 deletions

View File

@ -242,6 +242,7 @@ fn iterative_facet_number_ordered_iter<'t>(
// The itertools GroupBy iterator doesn't provide an owned version, we are therefore
// required to collect the result into an owned collection (a Vec).
// https://github.com/rust-itertools/itertools/issues/499
#[allow(clippy::needless_collect)]
let vec: Vec<_> = iter
.group_by(|(_, v)| *v)
.into_iter()
@ -284,6 +285,7 @@ fn iterative_facet_string_ordered_iter<'t>(
// The itertools GroupBy iterator doesn't provide an owned version, we are therefore
// required to collect the result into an owned collection (a Vec).
// https://github.com/rust-itertools/itertools/issues/499
#[allow(clippy::needless_collect)]
let vec: Vec<_> = iter
.group_by(|(_, v)| *v)
.into_iter()

View File

@ -179,6 +179,7 @@ impl<'t> Criterion for Attribute<'t> {
/// QueryPositionIterator is an Iterator over positions of a Query,
/// It contains iterators over words positions.
struct QueryPositionIterator<'t> {
#[allow(clippy::type_complexity)]
inner:
Vec<Peekable<Box<dyn Iterator<Item = heed::Result<((&'t str, u32), RoaringBitmap)>> + 't>>>,
}

View File

@ -96,6 +96,7 @@ pub trait Context<'c> {
&self,
docid: DocumentId,
) -> heed::Result<HashMap<String, RoaringBitmap>>;
#[allow(clippy::type_complexity)]
fn word_position_iterator(
&self,
word: &str,
@ -883,7 +884,7 @@ pub mod test {
let mut keys = word_docids.keys().collect::<Vec<_>>();
keys.sort_unstable();
let words_fst = fst::Set::from_iter(keys).unwrap().map_data(|v| Cow::Owned(v)).unwrap();
let words_fst = fst::Set::from_iter(keys).unwrap().map_data(Cow::Owned).unwrap();
TestContext {
words_fst,

View File

@ -123,6 +123,7 @@ impl<'a> FacetDistinctIter<'a> {
}
}
#[allow(clippy::drop_non_drop)]
fn facet_values_prefix_key(distinct: FieldId, id: DocumentId) -> [u8; FID_SIZE + DOCID_SIZE] {
concat_arrays!(distinct.to_be_bytes(), id.to_be_bytes())
}

View File

@ -110,7 +110,7 @@ mod test {
addition.execute().unwrap();
let fields_map = index.fields_ids_map(&txn).unwrap();
let fid = fields_map.id(&distinct).unwrap();
let fid = fields_map.id(distinct).unwrap();
let documents = DocumentsBatchReader::from_reader(Cursor::new(JSON.as_slice())).unwrap();
let map = (0..documents.documents_count() as u32).collect();
@ -133,7 +133,7 @@ mod test {
let s = value.to_string();
assert!(seen.insert(s));
}
Value::Array(values) => values.into_iter().for_each(|value| test(seen, value)),
Value::Array(values) => values.iter().for_each(|value| test(seen, value)),
}
}

View File

@ -38,9 +38,9 @@ where
if let Some(first_bound) = get_first_facet_value::<ByteSliceRefCodec>(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(()))
}
}

View File

@ -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}"));

View File

@ -50,6 +50,7 @@ struct AscendingFacetSort<'t, 'e> {
rtxn: &'t heed::RoTxn<'e>,
db: heed::Database<FacetGroupKeyCodec<ByteSliceRefCodec>, 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);

View File

@ -39,6 +39,7 @@ struct DescendingFacetSort<'t> {
rtxn: &'t heed::RoTxn<'t>,
db: heed::Database<FacetGroupKeyCodec<ByteSliceRefCodec>, 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<Self::Item> {
'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 },
@ -99,12 +100,10 @@ impl<'t> Iterator for DescendingFacetSort<'t> {
let iter = match self
.db
.remap_key_type::<FacetGroupKeyCodec<ByteSliceRefCodec>>()
.rev_range(
&self.rtxn,
&(Bound::Included(starting_key_below), end_key_kelow),
) {
.rev_range(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);

View File

@ -100,10 +100,10 @@ impl<'a> Filter<'a> {
}
}
if ors.len() > 1 {
ands.push(FilterCondition::Or(ors));
} else if ors.len() == 1 {
ands.push(ors.pop().unwrap());
match ors.len() {
0 => (),
1 => ands.push(ors.pop().unwrap()),
_ => ands.push(FilterCondition::Or(ors)),
}
}
Either::Right(rule) => {
@ -128,6 +128,7 @@ impl<'a> Filter<'a> {
Ok(Some(Self { condition: and }))
}
#[allow(clippy::should_implement_trait)]
pub fn from_str(expression: &'a str) -> Result<Option<Self>> {
let condition = match FilterCondition::parse(expression) {
Ok(Some(fc)) => Ok(fc),

View File

@ -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<OrderedF64Codec> {
let index = FacetIndex::<OrderedF64Codec>::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::<Vec<u32>>();
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);

View File

@ -125,10 +125,7 @@ impl<'t, A: AsRef<[u8]>> Matcher<'t, '_, A> {
words_positions: &mut impl Iterator<Item = (usize, usize, &'a Token<'a>)>,
matches: &mut Vec<Match>,
) -> bool {
let mut potential_matches = Vec::new();
// Add first match to potential matches.
potential_matches.push((token_position, word_position, partial.char_len()));
let mut potential_matches = vec![(token_position, word_position, partial.char_len())];
for (token_position, word_position, word) in words_positions {
partial = match partial.match_token(word) {