Resolve some clippys, format (#1144)

* cargo +nightly clippy --fix -Z unstable-options
This commit is contained in:
sigaloid
2021-08-25 19:46:00 -04:00
committed by GitHub
parent a1782dd172
commit 096ce7488e
11 changed files with 17 additions and 32 deletions

View File

@@ -86,12 +86,10 @@ impl Collector for StatsCollector {
fn merge_fruits(&self, segment_stats: Vec<Option<Stats>>) -> tantivy::Result<Option<Stats>> {
let mut stats = Stats::default();
for segment_stats_opt in segment_stats {
if let Some(segment_stats) = segment_stats_opt {
stats.count += segment_stats.count;
stats.sum += segment_stats.sum;
stats.squared_sum += segment_stats.squared_sum;
}
for segment_stats in segment_stats.into_iter().flatten() {
stats.count += segment_stats.count;
stats.sum += segment_stats.sum;
stats.squared_sum += segment_stats.squared_sum;
}
Ok(stats.non_zero_count())
}

View File

@@ -535,7 +535,7 @@ impl Index {
let mut damaged_files = HashSet::new();
for path in active_existing_files {
if !self.directory.validate_checksum(&path)? {
if !self.directory.validate_checksum(path)? {
damaged_files.insert((*path).clone());
}
}

View File

@@ -105,9 +105,7 @@ impl CompositeFastFieldSerializer {
&fastfield_accessor,
&mut estimations,
);
if let Some(broken_estimation) = estimations
.iter()
.find(|estimation| estimation.0 == f32::NAN)
if let Some(broken_estimation) = estimations.iter().find(|estimation| estimation.0.is_nan())
{
warn!(
"broken estimation for fast field codec {}",

View File

@@ -141,7 +141,7 @@ const LOREM: &str = "Doc Lorem ipsum dolor sit amet, consectetur adipiscing elit
fn get_text() -> String {
use rand::seq::SliceRandom;
let mut rng = thread_rng();
let tokens: Vec<_> = LOREM.split(" ").collect();
let tokens: Vec<_> = LOREM.split(' ').collect();
let random_val = rng.gen_range(0..20);
(0..random_val)

View File

@@ -150,7 +150,7 @@ impl TermOrdinalMapping {
.iter()
.flat_map(|term_ordinals| term_ordinals.iter().cloned().max())
.max()
.unwrap_or_else(TermOrdinal::default)
.unwrap_or_default()
}
}
@@ -966,7 +966,7 @@ impl IndexMerger {
doc_id_and_positions.sort_unstable_by_key(|&(doc_id, _, _)| doc_id);
for (doc_id, term_freq, positions) in &doc_id_and_positions {
let delta_positions = delta_computer.compute_delta(&positions);
let delta_positions = delta_computer.compute_delta(positions);
field_serializer.write_doc(*doc_id, *term_freq, delta_positions);
}
doc_id_and_positions.clear();

View File

@@ -260,9 +260,7 @@ mod tests {
let fallback_bitset = DeleteBitSet::for_test(&[0], 100);
assert_eq!(
postings.doc_freq_given_deletes(
segment_reader
.delete_bitset()
.unwrap_or_else(|| &&fallback_bitset)
segment_reader.delete_bitset().unwrap_or(&fallback_bitset)
),
2
);
@@ -341,9 +339,7 @@ mod tests {
let fallback_bitset = DeleteBitSet::for_test(&[0], 100);
assert_eq!(
postings.doc_freq_given_deletes(
segment_reader
.delete_bitset()
.unwrap_or_else(|| &&fallback_bitset)
segment_reader.delete_bitset().unwrap_or(&fallback_bitset)
),
2
);
@@ -453,9 +449,7 @@ mod tests {
let fallback_bitset = DeleteBitSet::for_test(&[0], 100);
assert_eq!(
postings.doc_freq_given_deletes(
segment_reader
.delete_bitset()
.unwrap_or_else(|| &&fallback_bitset)
segment_reader.delete_bitset().unwrap_or(&fallback_bitset)
),
2
);

View File

@@ -209,7 +209,7 @@ impl BlockSegmentPostings {
#[inline]
pub(crate) fn full_block(&self) -> &[DocId; COMPRESSION_BLOCK_SIZE] {
debug_assert!(self.block_is_loaded());
&self.doc_decoder.full_output()
self.doc_decoder.full_output()
}
/// Return the document at index `idx` of the block.

View File

@@ -443,10 +443,8 @@ impl<W: Write> PostingsSerializer<W> {
let skip_data = self.skip_write.data();
VInt(skip_data.len() as u64).serialize(&mut self.output_write)?;
self.output_write.write_all(skip_data)?;
self.output_write.write_all(&self.postings_write[..])?;
} else {
self.output_write.write_all(&self.postings_write[..])?;
}
self.output_write.write_all(&self.postings_write[..])?;
self.skip_write.clear();
self.postings_write.clear();
self.bm25_weight = None;

View File

@@ -121,10 +121,7 @@ mod tests {
}
fn is_match(&self, state: &Self::State) -> bool {
match *state {
State::AfterA => true,
_ => false,
}
matches!(*state, State::AfterA)
}
fn accept(&self, state: &Self::State, byte: u8) -> Self::State {

View File

@@ -310,7 +310,7 @@ mod tests {
));
let query = BooleanQuery::from(vec![(Occur::Should, term_a), (Occur::Should, term_b)]);
let explanation = query.explain(&searcher, DocAddress::new(0, 0u32))?;
assert_nearly_equals!(explanation.value(), 0.6931472);
assert_nearly_equals!(explanation.value(), std::f32::consts::LN_2);
Ok(())
}
}

View File

@@ -157,7 +157,7 @@ pub use self::int_options::IntOptions;
/// A field name can be any character, must have at least one character
/// and must not start with a `-`.
pub fn is_valid_field_name(field_name: &str) -> bool {
field_name.len() > 0 && !field_name.starts_with('-')
!field_name.is_empty() && !field_name.starts_with('-')
}
#[cfg(test)]