From dc0aa3d73441a9eb7b1947e5afa9874d8013ef96 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Fri, 1 Aug 2025 11:38:16 +0900 Subject: [PATCH] Clippy and cleanups --- bitpacker/src/bitpacker.rs | 4 ++++ bitpacker/src/blocked_bitpacker.rs | 5 ++--- bitpacker/src/lib.rs | 2 ++ columnar/src/columnar/mod.rs | 2 ++ columnar/src/lib.rs | 2 +- common/src/bitset.rs | 3 ++- common/src/lib.rs | 4 +++- query-grammar/src/query_grammar.rs | 5 ++--- src/collector/facet_collector.rs | 1 - src/positions/mod.rs | 3 --- src/query/boolean_query/block_wand.rs | 1 - src/tokenizer/ascii_folding_filter.rs | 2 -- sstable/src/dictionary.rs | 14 ++++++-------- sstable/src/lib.rs | 2 ++ sstable/src/sstable_index_v3.rs | 2 +- stacker/src/fastcpy.rs | 3 +-- stacker/src/lib.rs | 2 -- 17 files changed, 28 insertions(+), 29 deletions(-) diff --git a/bitpacker/src/bitpacker.rs b/bitpacker/src/bitpacker.rs index 85b4eb7c3..537b24153 100644 --- a/bitpacker/src/bitpacker.rs +++ b/bitpacker/src/bitpacker.rs @@ -1,3 +1,7 @@ +// manual divceil actually generates code that is not optimal (to accept the full range of u32) and +// perf matters here. +#![allow(clippy::manual_div_ceil)] + use std::io; use std::ops::{Range, RangeInclusive}; diff --git a/bitpacker/src/blocked_bitpacker.rs b/bitpacker/src/blocked_bitpacker.rs index 9438bee41..392338607 100644 --- a/bitpacker/src/blocked_bitpacker.rs +++ b/bitpacker/src/blocked_bitpacker.rs @@ -140,10 +140,9 @@ impl BlockedBitpacker { pub fn iter(&self) -> impl Iterator + '_ { // todo performance: we could decompress a whole block and cache it instead let bitpacked_elems = self.offset_and_bits.len() * BLOCK_SIZE; - let iter = (0..bitpacked_elems) + (0..bitpacked_elems) .map(move |idx| self.get(idx)) - .chain(self.buffer.iter().cloned()); - iter + .chain(self.buffer.iter().cloned()) } } diff --git a/bitpacker/src/lib.rs b/bitpacker/src/lib.rs index ec78bdedd..cb50f0f0d 100644 --- a/bitpacker/src/lib.rs +++ b/bitpacker/src/lib.rs @@ -1,3 +1,5 @@ +// #[allow(clippy::manual_div_ceil)] + mod bitpacker; mod blocked_bitpacker; mod filter_vec; diff --git a/columnar/src/columnar/mod.rs b/columnar/src/columnar/mod.rs index 5b57e0298..1c1521490 100644 --- a/columnar/src/columnar/mod.rs +++ b/columnar/src/columnar/mod.rs @@ -1,3 +1,5 @@ +#![allow(clippy::manual_div_ceil)] + mod column_type; mod format_version; mod merge; diff --git a/columnar/src/lib.rs b/columnar/src/lib.rs index 30e09e8fa..257419e5f 100644 --- a/columnar/src/lib.rs +++ b/columnar/src/lib.rs @@ -17,7 +17,7 @@ //! column. //! - [column_values]: Stores the values of a column in a dense format. -#![cfg_attr(all(feature = "unstable", test), feature(test))] +// #![cfg_attr(all(feature = "unstable", test), feature(test))] #[cfg(test)] #[macro_use] diff --git a/common/src/bitset.rs b/common/src/bitset.rs index c930e6fe8..d7128f258 100644 --- a/common/src/bitset.rs +++ b/common/src/bitset.rs @@ -9,7 +9,7 @@ use crate::ByteCount; pub struct TinySet(u64); impl fmt::Debug for TinySet { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.into_iter().collect::>().fmt(f) } } @@ -182,6 +182,7 @@ pub struct BitSet { max_value: u32, } +#[inline(always)] fn num_buckets(max_val: u32) -> u32 { (max_val + 63u32) / 64u32 } diff --git a/common/src/lib.rs b/common/src/lib.rs index 4e64af11c..cb8145ef6 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,4 +1,6 @@ -#![allow(clippy::len_without_is_empty)] +// manual divceil actually generates code that is not optimal (to accept the full range of u32) and +// perf matters here. +#![allow(clippy::len_without_is_empty, clippy::manual_div_ceil)] use std::ops::Deref; diff --git a/query-grammar/src/query_grammar.rs b/query-grammar/src/query_grammar.rs index 0030c776c..85df78804 100644 --- a/query-grammar/src/query_grammar.rs +++ b/query-grammar/src/query_grammar.rs @@ -305,15 +305,14 @@ fn term_group_infallible(inp: &str) -> JResult<&str, UserInputAst> { let (inp, (field_name, _, _, _)) = tuple((field_name, multispace0, char('('), multispace0))(inp).expect("precondition failed"); - let res = delimited_infallible( + delimited_infallible( nothing, map(ast_infallible, |(mut ast, errors)| { ast.set_default_field(field_name.to_string()); (ast, errors) }), opt_i_err(char(')'), "expected ')'"), - )(inp); - res + )(inp) } fn exists(inp: &str) -> IResult<&str, UserInputLeaf> { diff --git a/src/collector/facet_collector.rs b/src/collector/facet_collector.rs index 183c245ca..a94ec03e8 100644 --- a/src/collector/facet_collector.rs +++ b/src/collector/facet_collector.rs @@ -484,7 +484,6 @@ impl FacetCounts { #[cfg(test)] mod tests { use std::collections::BTreeSet; - use std::iter; use columnar::Dictionary; use rand::distributions::Uniform; diff --git a/src/positions/mod.rs b/src/positions/mod.rs index b6ae9dcad..544819aef 100644 --- a/src/positions/mod.rs +++ b/src/positions/mod.rs @@ -40,9 +40,6 @@ const COMPRESSION_BLOCK_SIZE: usize = BitPacker4x::BLOCK_LEN; #[cfg(test)] pub(crate) mod tests { - - use std::iter; - use proptest::prelude::*; use proptest::sample::select; diff --git a/src/query/boolean_query/block_wand.rs b/src/query/boolean_query/block_wand.rs index d2803c82d..85a16df94 100644 --- a/src/query/boolean_query/block_wand.rs +++ b/src/query/boolean_query/block_wand.rs @@ -302,7 +302,6 @@ fn is_sorted>(mut it: I) -> bool { mod tests { use std::cmp::Ordering; use std::collections::BinaryHeap; - use std::iter; use proptest::prelude::*; diff --git a/src/tokenizer/ascii_folding_filter.rs b/src/tokenizer/ascii_folding_filter.rs index 9a7ba8316..1f6df365d 100644 --- a/src/tokenizer/ascii_folding_filter.rs +++ b/src/tokenizer/ascii_folding_filter.rs @@ -1561,8 +1561,6 @@ fn to_ascii(text: &str, output: &mut String) { #[cfg(test)] mod tests { - use std::iter; - use super::to_ascii; use crate::tokenizer::{AsciiFoldingFilter, RawTokenizer, SimpleTokenizer, TextAnalyzer}; diff --git a/sstable/src/dictionary.rs b/sstable/src/dictionary.rs index 4b4dd0275..b1cf2c3b7 100644 --- a/sstable/src/dictionary.rs +++ b/sstable/src/dictionary.rs @@ -308,10 +308,9 @@ impl Dictionary { } } _ => { - return Err(io::Error::new( - io::ErrorKind::Other, - format!("Unsupported sstable version, expected one of [2, 3], found {version}"), - )); + return Err(io::Error::other(format!( + "Unsupported sstable version, expected one of [2, 3], found {version}" + ))); } }; @@ -697,10 +696,9 @@ mod tests { fn read_bytes(&self, range: Range) -> std::io::Result { let allowed_range = self.allowed_range.lock().unwrap(); if !allowed_range.contains(&range.start) || !allowed_range.contains(&(range.end - 1)) { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - format!("invalid range, allowed {allowed_range:?}, requested {range:?}"), - )); + return Err(std::io::Error::other(format!( + "invalid range, allowed {allowed_range:?}, requested {range:?}" + ))); } Ok(self.bytes.slice(range)) diff --git a/sstable/src/lib.rs b/sstable/src/lib.rs index 82461c363..54dc3851c 100644 --- a/sstable/src/lib.rs +++ b/sstable/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::manual_div_ceil)] + //! `tantivy_sstable` is a crate that provides a sorted string table data structure. //! //! It is used in `tantivy` to store the term dictionary. diff --git a/sstable/src/sstable_index_v3.rs b/sstable/src/sstable_index_v3.rs index c2ab1fa07..5e948073c 100644 --- a/sstable/src/sstable_index_v3.rs +++ b/sstable/src/sstable_index_v3.rs @@ -394,7 +394,7 @@ impl SSTableIndexBuilder { fn fst_error_to_io_error(error: tantivy_fst::Error) -> io::Error { match error { - tantivy_fst::Error::Fst(fst_error) => io::Error::new(io::ErrorKind::Other, fst_error), + tantivy_fst::Error::Fst(fst_error) => io::Error::other(fst_error), tantivy_fst::Error::Io(ioerror) => ioerror, } } diff --git a/stacker/src/fastcpy.rs b/stacker/src/fastcpy.rs index 8195e17f0..04bb2ad55 100644 --- a/stacker/src/fastcpy.rs +++ b/stacker/src/fastcpy.rs @@ -10,8 +10,7 @@ pub fn fast_short_slice_copy(src: &[u8], dst: &mut [u8]) { #[track_caller] fn len_mismatch_fail(dst_len: usize, src_len: usize) -> ! { panic!( - "source slice length ({}) does not match destination slice length ({})", - src_len, dst_len, + "source slice length ({src_len}) does not match destination slice length ({dst_len})", ); } diff --git a/stacker/src/lib.rs b/stacker/src/lib.rs index 7eda3cff9..07d50af8b 100644 --- a/stacker/src/lib.rs +++ b/stacker/src/lib.rs @@ -1,5 +1,3 @@ -#![cfg_attr(all(feature = "unstable", test), feature(test))] - #[cfg(all(test, feature = "unstable"))] extern crate test;