Skip to content

Commit 519e5d2

Browse files
committed
clippy warnings
1 parent df2d52a commit 519e5d2

File tree

9 files changed

+24
-21
lines changed

9 files changed

+24
-21
lines changed

bitpacker/src/bitpacker.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,25 @@ impl BitUnpacker {
129129
//
130130
// This methods panics if `num_bits` is > 32.
131131
fn get_batch_u32s(&self, start_idx: u32, data: &[u8], output: &mut [u32]) {
132-
let start_idx = start_idx as usize;
133132
assert!(
134133
self.bit_width() <= 32,
135134
"Bitwidth must be <= 32 to use this method."
136135
);
137136

138-
let end_idx = start_idx + output.len();
137+
let end_idx: u32 = start_idx + output.len() as u32;
139138

140-
let end_bit_read = end_idx * self.num_bits;
139+
// We use `usize` here to avoid overflow issues.
140+
let end_bit_read = (end_idx as usize) * self.num_bits;
141141
let end_byte_read = (end_bit_read + 7) / 8;
142142
assert!(
143143
end_byte_read <= data.len(),
144144
"Requested index is out of bounds."
145145
);
146146

147147
// Simple slow implementation of get_batch_u32s, to deal with our ramps.
148-
let get_batch_ramp = |start_idx: usize, output: &mut [u32]| {
148+
let get_batch_ramp = |start_idx: u32, output: &mut [u32]| {
149149
for (out, idx) in output.iter_mut().zip(start_idx..) {
150-
*out = self.get(idx as u32, data) as u32;
150+
*out = self.get(idx, data) as u32;
151151
}
152152
};
153153

@@ -160,25 +160,25 @@ impl BitUnpacker {
160160
// We want the start of the fast track to start align with bytes.
161161
// A sufficient condition is to start with an idx that is a multiple of 8,
162162
// so highway start is the closest multiple of 8 that is >= start_idx.
163-
let entrance_ramp_len = 8 - (start_idx % 8) % 8;
163+
let entrance_ramp_len: u32 = 8 - (start_idx % 8) % 8;
164164

165-
let highway_start: usize = start_idx + entrance_ramp_len;
165+
let highway_start: u32 = start_idx + entrance_ramp_len;
166166

167-
if highway_start + BitPacker1x::BLOCK_LEN > end_idx {
167+
if highway_start + (BitPacker1x::BLOCK_LEN as u32) > end_idx {
168168
// We don't have enough values to have even a single block of highway.
169169
// Let's just supply the values the simple way.
170170
get_batch_ramp(start_idx, output);
171171
return;
172172
}
173173

174-
let num_blocks: usize = (end_idx - highway_start) / BitPacker1x::BLOCK_LEN;
174+
let num_blocks: usize = (end_idx - highway_start) as usize / BitPacker1x::BLOCK_LEN;
175175

176176
// Entrance ramp
177-
get_batch_ramp(start_idx, &mut output[..entrance_ramp_len]);
177+
get_batch_ramp(start_idx, &mut output[..entrance_ramp_len as usize]);
178178

179179
// Highway
180-
let mut offset = (highway_start * self.num_bits) / 8;
181-
let mut output_cursor = highway_start - start_idx;
180+
let mut offset = (highway_start as usize * self.num_bits) / 8;
181+
let mut output_cursor = (highway_start - start_idx) as usize;
182182
for _ in 0..num_blocks {
183183
offset += BitPacker1x.decompress(
184184
&data[offset..],
@@ -189,7 +189,7 @@ impl BitUnpacker {
189189
}
190190

191191
// Exit ramp
192-
let highway_end = highway_start + num_blocks * BitPacker1x::BLOCK_LEN;
192+
let highway_end: u32 = highway_start + (num_blocks * BitPacker1x::BLOCK_LEN) as u32;
193193
get_batch_ramp(highway_end, &mut output[output_cursor..]);
194194
}
195195

bitpacker/src/blocked_bitpacker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct BlockedBitpackerEntryMetaData {
3434

3535
impl BlockedBitpackerEntryMetaData {
3636
fn new(offset: u64, num_bits: u8, base_value: u64) -> Self {
37-
let encoded = offset | (num_bits as u64) << (64 - 8);
37+
let encoded = offset | (u64::from(num_bits) << (64 - 8));
3838
Self {
3939
encoded,
4040
base_value,

columnar/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ fn test_columnar_merging_number_columns() {
715715
// TODO test required_columns
716716
// TODO document edge case: required_columns incompatible with values.
717717

718+
#[allow(clippy::type_complexity)]
718719
fn columnar_docs_and_remap(
719720
) -> impl Strategy<Value = (Vec<Vec<Vec<(&'static str, ColumnValue)>>>, Vec<RowAddr>)> {
720721
proptest::collection::vec(columnar_docs_strategy(), 2..=3).prop_flat_map(

src/indexer/index_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,7 @@ mod tests {
25532553
#[test]
25542554
fn test_writer_options_validation() {
25552555
let mut schema_builder = Schema::builder();
2556-
let field = schema_builder.add_bool_field("example", STORED);
2556+
let _field = schema_builder.add_bool_field("example", STORED);
25572557
let index = Index::create_in_ram(schema_builder.build());
25582558

25592559
let opt_wo_threads = IndexWriterOptions::builder().num_worker_threads(0).build();

src/postings/skip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn encode_bitwidth(bitwidth: u8, delta_1: bool) -> u8 {
1515
}
1616

1717
fn decode_bitwidth(raw_bitwidth: u8) -> (u8, bool) {
18-
let delta_1 = (raw_bitwidth >> 6 & 1) != 0;
18+
let delta_1 = ((raw_bitwidth >> 6) & 1) != 0;
1919
let bitwidth = raw_bitwidth & 0x3f;
2020
(bitwidth, delta_1)
2121
}

src/schema/document/default_document.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::schema::field_type::ValueParsingError;
1515
use crate::schema::{Facet, Field, NamedFieldDocument, OwnedValue, Schema};
1616
use crate::tokenizer::PreTokenizedString;
1717

18-
#[repr(packed)]
18+
#[repr(C, packed)]
1919
#[derive(Debug, Clone)]
2020
/// A field value pair in the compact tantivy document
2121
struct FieldValueAddr {
@@ -480,7 +480,7 @@ impl<'a> CompactDocValue<'a> {
480480
type Addr = u32;
481481

482482
#[derive(Clone, Copy, Default)]
483-
#[repr(packed)]
483+
#[repr(C, packed)]
484484
/// The value type and the address to its payload in the container.
485485
struct ValueAddr {
486486
type_id: ValueType,
@@ -734,7 +734,7 @@ mod tests {
734734

735735
#[test]
736736
fn test_json_value() {
737-
let json_str = r#"{
737+
let json_str = r#"{
738738
"toto": "titi",
739739
"float": -0.2,
740740
"bool": true,

sstable/src/delta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where
8989

9090
fn encode_keep_add(&mut self, keep_len: usize, add_len: usize) {
9191
if keep_len < FOUR_BIT_LIMITS && add_len < FOUR_BIT_LIMITS {
92-
let b = (keep_len | add_len << 4) as u8;
92+
let b = (keep_len | (add_len << 4)) as u8;
9393
self.block.extend_from_slice(&[b])
9494
} else {
9595
let mut buf = [VINT_MODE; 20];

sstable/src/dictionary.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::needless_borrows_for_generic_args)]
2+
13
use std::cmp::Ordering;
24
use std::io;
35
use std::marker::PhantomData;

stacker/src/memory_arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Addr {
5454

5555
#[inline]
5656
fn new(page_id: usize, local_addr: usize) -> Addr {
57-
Addr((page_id << NUM_BITS_PAGE_ADDR | local_addr) as u32)
57+
Addr(((page_id << NUM_BITS_PAGE_ADDR) | local_addr) as u32)
5858
}
5959

6060
#[inline]

0 commit comments

Comments
 (0)