Skip to content

Commit

Permalink
Resolve some clippys, format (#1144)
Browse files Browse the repository at this point in the history
* cargo +nightly clippy --fix -Z unstable-options
  • Loading branch information
sigaloid authored Aug 25, 2021
1 parent a1782dd commit 096ce74
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 32 deletions.
10 changes: 4 additions & 6 deletions examples/custom_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/fastfield/serializer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}",
Expand Down
2 changes: 1 addition & 1 deletion src/functional_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/indexer/merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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();
Expand Down
12 changes: 3 additions & 9 deletions src/indexer/merger_sorted_index_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion src/postings/block_segment_postings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions src/postings/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/query/automaton_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/query/boolean_query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
2 changes: 1 addition & 1 deletion src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 096ce74

Please sign in to comment.