From 519e5d2ed1ab1e28b02930c82d177179ebf50489 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Wed, 5 Mar 2025 10:55:34 +0100 Subject: [PATCH] clippy warnings --- bitpacker/src/bitpacker.rs | 26 ++++++++++++------------- bitpacker/src/blocked_bitpacker.rs | 2 +- columnar/src/tests.rs | 1 + src/indexer/index_writer.rs | 2 +- src/postings/skip.rs | 2 +- src/schema/document/default_document.rs | 6 +++--- sstable/src/delta.rs | 2 +- sstable/src/dictionary.rs | 2 ++ stacker/src/memory_arena.rs | 2 +- 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/bitpacker/src/bitpacker.rs b/bitpacker/src/bitpacker.rs index b5e5a3b89..85b4eb7c3 100644 --- a/bitpacker/src/bitpacker.rs +++ b/bitpacker/src/bitpacker.rs @@ -129,15 +129,15 @@ impl BitUnpacker { // // This methods panics if `num_bits` is > 32. fn get_batch_u32s(&self, start_idx: u32, data: &[u8], output: &mut [u32]) { - let start_idx = start_idx as usize; assert!( self.bit_width() <= 32, "Bitwidth must be <= 32 to use this method." ); - let end_idx = start_idx + output.len(); + let end_idx: u32 = start_idx + output.len() as u32; - let end_bit_read = end_idx * self.num_bits; + // We use `usize` here to avoid overflow issues. + let end_bit_read = (end_idx as usize) * self.num_bits; let end_byte_read = (end_bit_read + 7) / 8; assert!( end_byte_read <= data.len(), @@ -145,9 +145,9 @@ impl BitUnpacker { ); // Simple slow implementation of get_batch_u32s, to deal with our ramps. - let get_batch_ramp = |start_idx: usize, output: &mut [u32]| { + let get_batch_ramp = |start_idx: u32, output: &mut [u32]| { for (out, idx) in output.iter_mut().zip(start_idx..) { - *out = self.get(idx as u32, data) as u32; + *out = self.get(idx, data) as u32; } }; @@ -160,25 +160,25 @@ impl BitUnpacker { // We want the start of the fast track to start align with bytes. // A sufficient condition is to start with an idx that is a multiple of 8, // so highway start is the closest multiple of 8 that is >= start_idx. - let entrance_ramp_len = 8 - (start_idx % 8) % 8; + let entrance_ramp_len: u32 = 8 - (start_idx % 8) % 8; - let highway_start: usize = start_idx + entrance_ramp_len; + let highway_start: u32 = start_idx + entrance_ramp_len; - if highway_start + BitPacker1x::BLOCK_LEN > end_idx { + if highway_start + (BitPacker1x::BLOCK_LEN as u32) > end_idx { // We don't have enough values to have even a single block of highway. // Let's just supply the values the simple way. get_batch_ramp(start_idx, output); return; } - let num_blocks: usize = (end_idx - highway_start) / BitPacker1x::BLOCK_LEN; + let num_blocks: usize = (end_idx - highway_start) as usize / BitPacker1x::BLOCK_LEN; // Entrance ramp - get_batch_ramp(start_idx, &mut output[..entrance_ramp_len]); + get_batch_ramp(start_idx, &mut output[..entrance_ramp_len as usize]); // Highway - let mut offset = (highway_start * self.num_bits) / 8; - let mut output_cursor = highway_start - start_idx; + let mut offset = (highway_start as usize * self.num_bits) / 8; + let mut output_cursor = (highway_start - start_idx) as usize; for _ in 0..num_blocks { offset += BitPacker1x.decompress( &data[offset..], @@ -189,7 +189,7 @@ impl BitUnpacker { } // Exit ramp - let highway_end = highway_start + num_blocks * BitPacker1x::BLOCK_LEN; + let highway_end: u32 = highway_start + (num_blocks * BitPacker1x::BLOCK_LEN) as u32; get_batch_ramp(highway_end, &mut output[output_cursor..]); } diff --git a/bitpacker/src/blocked_bitpacker.rs b/bitpacker/src/blocked_bitpacker.rs index 3b372229d..e82a92de7 100644 --- a/bitpacker/src/blocked_bitpacker.rs +++ b/bitpacker/src/blocked_bitpacker.rs @@ -34,7 +34,7 @@ struct BlockedBitpackerEntryMetaData { impl BlockedBitpackerEntryMetaData { fn new(offset: u64, num_bits: u8, base_value: u64) -> Self { - let encoded = offset | (num_bits as u64) << (64 - 8); + let encoded = offset | (u64::from(num_bits) << (64 - 8)); Self { encoded, base_value, diff --git a/columnar/src/tests.rs b/columnar/src/tests.rs index b3d435b3e..a5ab9d0ff 100644 --- a/columnar/src/tests.rs +++ b/columnar/src/tests.rs @@ -715,6 +715,7 @@ fn test_columnar_merging_number_columns() { // TODO test required_columns // TODO document edge case: required_columns incompatible with values. +#[allow(clippy::type_complexity)] fn columnar_docs_and_remap( ) -> impl Strategy>>, Vec)> { proptest::collection::vec(columnar_docs_strategy(), 2..=3).prop_flat_map( diff --git a/src/indexer/index_writer.rs b/src/indexer/index_writer.rs index 6bbb6acc4..c15d6d456 100644 --- a/src/indexer/index_writer.rs +++ b/src/indexer/index_writer.rs @@ -2553,7 +2553,7 @@ mod tests { #[test] fn test_writer_options_validation() { let mut schema_builder = Schema::builder(); - let field = schema_builder.add_bool_field("example", STORED); + let _field = schema_builder.add_bool_field("example", STORED); let index = Index::create_in_ram(schema_builder.build()); let opt_wo_threads = IndexWriterOptions::builder().num_worker_threads(0).build(); diff --git a/src/postings/skip.rs b/src/postings/skip.rs index fe5a8df88..c36690444 100644 --- a/src/postings/skip.rs +++ b/src/postings/skip.rs @@ -15,7 +15,7 @@ fn encode_bitwidth(bitwidth: u8, delta_1: bool) -> u8 { } fn decode_bitwidth(raw_bitwidth: u8) -> (u8, bool) { - let delta_1 = (raw_bitwidth >> 6 & 1) != 0; + let delta_1 = ((raw_bitwidth >> 6) & 1) != 0; let bitwidth = raw_bitwidth & 0x3f; (bitwidth, delta_1) } diff --git a/src/schema/document/default_document.rs b/src/schema/document/default_document.rs index 2c3486800..915b685aa 100644 --- a/src/schema/document/default_document.rs +++ b/src/schema/document/default_document.rs @@ -15,7 +15,7 @@ use crate::schema::field_type::ValueParsingError; use crate::schema::{Facet, Field, NamedFieldDocument, OwnedValue, Schema}; use crate::tokenizer::PreTokenizedString; -#[repr(packed)] +#[repr(C, packed)] #[derive(Debug, Clone)] /// A field value pair in the compact tantivy document struct FieldValueAddr { @@ -480,7 +480,7 @@ impl<'a> CompactDocValue<'a> { type Addr = u32; #[derive(Clone, Copy, Default)] -#[repr(packed)] +#[repr(C, packed)] /// The value type and the address to its payload in the container. struct ValueAddr { type_id: ValueType, @@ -734,7 +734,7 @@ mod tests { #[test] fn test_json_value() { - let json_str = r#"{ + let json_str = r#"{ "toto": "titi", "float": -0.2, "bool": true, diff --git a/sstable/src/delta.rs b/sstable/src/delta.rs index e627f987e..fba996ac0 100644 --- a/sstable/src/delta.rs +++ b/sstable/src/delta.rs @@ -89,7 +89,7 @@ where fn encode_keep_add(&mut self, keep_len: usize, add_len: usize) { if keep_len < FOUR_BIT_LIMITS && add_len < FOUR_BIT_LIMITS { - let b = (keep_len | add_len << 4) as u8; + let b = (keep_len | (add_len << 4)) as u8; self.block.extend_from_slice(&[b]) } else { let mut buf = [VINT_MODE; 20]; diff --git a/sstable/src/dictionary.rs b/sstable/src/dictionary.rs index 3748daed6..c58a0a40e 100644 --- a/sstable/src/dictionary.rs +++ b/sstable/src/dictionary.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_borrows_for_generic_args)] + use std::cmp::Ordering; use std::io; use std::marker::PhantomData; diff --git a/stacker/src/memory_arena.rs b/stacker/src/memory_arena.rs index 6348da670..383b96438 100644 --- a/stacker/src/memory_arena.rs +++ b/stacker/src/memory_arena.rs @@ -54,7 +54,7 @@ impl Addr { #[inline] fn new(page_id: usize, local_addr: usize) -> Addr { - Addr((page_id << NUM_BITS_PAGE_ADDR | local_addr) as u32) + Addr(((page_id << NUM_BITS_PAGE_ADDR) | local_addr) as u32) } #[inline]