diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f6449c1e0..f7acfbebd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,6 +48,24 @@ jobs: command: test args: --release --all + clippy: + name: Run Clippy + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: clippy + - name: Cache dependencies + uses: Swatinem/rust-cache@v2.0.0 + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + fmt: name: Run Rustfmt runs-on: ubuntu-20.04 diff --git a/bors.toml b/bors.toml index 73324892f..8ba0eed94 100644 --- a/bors.toml +++ b/bors.toml @@ -2,6 +2,7 @@ status = [ 'Tests on ubuntu-20.04', 'Tests on macos-latest', 'Tests on windows-latest', + 'Run Clippy', 'Run Rustfmt', ] # 3 hours timeout diff --git a/milli/src/search/criteria/mod.rs b/milli/src/search/criteria/mod.rs index 8d0e3af05..76718c8ec 100644 --- a/milli/src/search/criteria/mod.rs +++ b/milli/src/search/criteria/mod.rs @@ -431,20 +431,17 @@ pub fn resolve_phrase(ctx: &dyn Context, phrase: &[Option]) -> Result bitmaps.push(m), diff --git a/milli/src/search/criteria/proximity.rs b/milli/src/search/criteria/proximity.rs index d51047821..880b3e1ba 100644 --- a/milli/src/search/criteria/proximity.rs +++ b/milli/src/search/criteria/proximity.rs @@ -488,7 +488,7 @@ fn resolve_plane_sweep_candidates( } // make a consecutive plane-sweep on the subgroup of words. let mut subgroup = Vec::with_capacity(words.len()); - for word in words.into_iter().map(|w| w.as_deref().unwrap()) { + for word in words.iter().map(|w| w.as_deref().unwrap()) { match words_positions.get(word) { Some(positions) => { subgroup.push(positions.iter().map(|p| (p, 0, p)).collect()) diff --git a/milli/src/search/matches/matching_words.rs b/milli/src/search/matches/matching_words.rs index 1f6ead8a9..25d447d0c 100644 --- a/milli/src/search/matches/matching_words.rs +++ b/milli/src/search/matches/matching_words.rs @@ -225,7 +225,7 @@ fn bytes_to_highlight(source: &str, target: &str) -> usize { for (col, char_t) in target.chars().enumerate() { let col = col + 1; let last_match_row = *last_row.get(&char_t).unwrap_or(&0); - let cost = if char_s == char_t { 0 } else { 1 }; + let cost = usize::from(char_s != char_t); let dist_add = matrix[(row, col + 1)] + 1; let dist_del = matrix[(row + 1, col)] + 1; diff --git a/milli/src/search/query_tree.rs b/milli/src/search/query_tree.rs index 5042f4762..a9c1ac29f 100755 --- a/milli/src/search/query_tree.rs +++ b/milli/src/search/query_tree.rs @@ -589,11 +589,8 @@ fn create_matching_words( PrimitiveQueryPart::Phrase(words) => { let ids: Vec<_> = (0..words.len()).into_iter().map(|i| id + i as PrimitiveWordId).collect(); - let words = words - .into_iter() - .filter_map(|w| w) - .map(|w| MatchingWord::new(w, 0, false)) - .collect(); + let words = + words.into_iter().flatten().map(|w| MatchingWord::new(w, 0, false)).collect(); matching_words.push((words, ids)); } } diff --git a/milli/src/update/facet/incremental.rs b/milli/src/update/facet/incremental.rs index c6735224d..fd253b146 100644 --- a/milli/src/update/facet/incremental.rs +++ b/milli/src/update/facet/incremental.rs @@ -329,7 +329,7 @@ impl FacetsUpdateIncrementalInner { let key = FacetGroupKey { field_id, level, left_bound: insertion_key.left_bound.clone() }; - let value = FacetGroupValue { size: size_left as u8, bitmap: values_left }; + let value = FacetGroupValue { size: size_left, bitmap: values_left }; (key, value) }; @@ -345,7 +345,7 @@ impl FacetsUpdateIncrementalInner { } let key = FacetGroupKey { field_id, level, left_bound: right_left_bound.to_vec() }; - let value = FacetGroupValue { size: size_right as u8, bitmap: values_right }; + let value = FacetGroupValue { size: size_right, bitmap: values_right }; (key, value) }; drop(iter); @@ -373,8 +373,7 @@ impl FacetsUpdateIncrementalInner { 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)?; + let result = self.insert_in_level(txn, field_id, highest_level, facet_value, docids)?; match result { InsertionResult::InPlace => return Ok(()), InsertionResult::Expand => return Ok(()), @@ -425,7 +424,7 @@ impl FacetsUpdateIncrementalInner { level: highest_level + 1, left_bound: first_key.unwrap().left_bound, }; - let value = FacetGroupValue { size: group_size as u8, bitmap: values }; + let value = FacetGroupValue { size: group_size, bitmap: values }; to_add.push((key.into_owned(), value)); } // now we add the rest of the level, in case its size is > group_size * min_level_size @@ -584,8 +583,7 @@ impl FacetsUpdateIncrementalInner { } 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)?; + let result = self.delete_in_level(txn, field_id, highest_level, facet_value, docids)?; match result { DeletionResult::InPlace => return Ok(()), DeletionResult::Reduce { .. } => return Ok(()), diff --git a/milli/src/update/index_documents/extract/extract_docid_word_positions.rs b/milli/src/update/index_documents/extract/extract_docid_word_positions.rs index f1d595039..8eae0caee 100644 --- a/milli/src/update/index_documents/extract/extract_docid_word_positions.rs +++ b/milli/src/update/index_documents/extract/extract_docid_word_positions.rs @@ -80,7 +80,7 @@ pub fn extract_docid_word_positions( .map_err(|_| SerializationError::InvalidNumberSerialization)?; let position = absolute_from_relative_position(field_id, position); docid_word_positions_sorter - .insert(&key_buffer, &position.to_ne_bytes())?; + .insert(&key_buffer, position.to_ne_bytes())?; } } } diff --git a/milli/src/update/index_documents/extract/extract_facet_string_docids.rs b/milli/src/update/index_documents/extract/extract_facet_string_docids.rs index 221356ba0..182538683 100644 --- a/milli/src/update/index_documents/extract/extract_facet_string_docids.rs +++ b/milli/src/update/index_documents/extract/extract_facet_string_docids.rs @@ -43,7 +43,7 @@ pub fn extract_facet_string_docids( let key_bytes = FacetGroupKeyCodec::::bytes_encode(&key).unwrap(); // document id is encoded in native-endian because of the CBO roaring bitmap codec - facet_string_docids_sorter.insert(&key_bytes, &document_id.to_ne_bytes())?; + facet_string_docids_sorter.insert(&key_bytes, document_id.to_ne_bytes())?; } sorter_into_reader(facet_string_docids_sorter, indexer) diff --git a/milli/src/update/index_documents/extract/extract_word_pair_proximity_docids.rs b/milli/src/update/index_documents/extract/extract_word_pair_proximity_docids.rs index 0c7700a33..6707fc268 100644 --- a/milli/src/update/index_documents/extract/extract_word_pair_proximity_docids.rs +++ b/milli/src/update/index_documents/extract/extract_word_pair_proximity_docids.rs @@ -145,7 +145,7 @@ fn document_word_positions_into_sorter( key_buffer.push(0); key_buffer.extend_from_slice(w2.as_bytes()); - word_pair_proximity_docids_sorter.insert(&key_buffer, &document_id.to_ne_bytes())?; + word_pair_proximity_docids_sorter.insert(&key_buffer, document_id.to_ne_bytes())?; } Ok(()) diff --git a/milli/src/update/index_documents/extract/extract_word_position_docids.rs b/milli/src/update/index_documents/extract/extract_word_position_docids.rs index d4a3eda2c..d95db4157 100644 --- a/milli/src/update/index_documents/extract/extract_word_position_docids.rs +++ b/milli/src/update/index_documents/extract/extract_word_position_docids.rs @@ -41,7 +41,7 @@ pub fn extract_word_position_docids( key_buffer.extend_from_slice(word_bytes); key_buffer.extend_from_slice(&position.to_be_bytes()); - word_position_docids_sorter.insert(&key_buffer, &document_id.to_ne_bytes())?; + word_position_docids_sorter.insert(&key_buffer, document_id.to_ne_bytes())?; } } diff --git a/milli/src/update/index_documents/transform.rs b/milli/src/update/index_documents/transform.rs index 7c9a912b3..59f18b22d 100644 --- a/milli/src/update/index_documents/transform.rs +++ b/milli/src/update/index_documents/transform.rs @@ -248,7 +248,7 @@ impl<'a, 'i> Transform<'a, 'i> { skip_insertion = true; } else { // we associate the base document with the new key, everything will get merged later. - self.original_sorter.insert(&docid.to_be_bytes(), base_obkv)?; + self.original_sorter.insert(docid.to_be_bytes(), base_obkv)?; match self.flatten_from_fields_ids_map(KvReader::new(base_obkv))? { Some(buffer) => { self.flattened_sorter.insert(docid.to_be_bytes(), &buffer)? @@ -261,7 +261,7 @@ impl<'a, 'i> Transform<'a, 'i> { if !skip_insertion { self.new_documents_ids.insert(docid); // We use the extracted/generated user id as the key for this document. - self.original_sorter.insert(&docid.to_be_bytes(), obkv_buffer.clone())?; + self.original_sorter.insert(docid.to_be_bytes(), obkv_buffer.clone())?; match self.flatten_from_fields_ids_map(KvReader::new(&obkv_buffer))? { Some(buffer) => self.flattened_sorter.insert(docid.to_be_bytes(), &buffer)?, diff --git a/milli/src/update/words_prefixes_fst.rs b/milli/src/update/words_prefixes_fst.rs index 193956c7a..57fed0922 100644 --- a/milli/src/update/words_prefixes_fst.rs +++ b/milli/src/update/words_prefixes_fst.rs @@ -36,7 +36,7 @@ impl<'t, 'u, 'i> WordsPrefixesFst<'t, 'u, 'i> { /// Default value is `4` bytes. This value must be between 1 and 25 will be clamped /// to these bounds, otherwise. pub fn max_prefix_length(&mut self, value: usize) -> &mut Self { - self.max_prefix_length = value.min(25).max(1); // clamp [1, 25] + self.max_prefix_length = value.clamp(1, 25); self }