Fixing clippy comments

This commit is contained in:
Paul Masurel
2022-02-01 10:24:05 +09:00
parent 0d8263cba1
commit 2069e3e52b
23 changed files with 61 additions and 26 deletions

View File

@@ -39,7 +39,6 @@ fn main() {
} else {
(est.to_string(), comp.to_string())
};
#[allow(clippy::all)]
let style = if comp == best_compression_ratio_codec.1 {
"Fb"
} else {
@@ -47,7 +46,7 @@ fn main() {
};
table.add_row(Row::new(vec![
Cell::new(&name.to_string()).style_spec("bFg"),
Cell::new(name).style_spec("bFg"),
Cell::new(&ratio_cell).style_spec(style),
Cell::new(&est_cell).style_spec(""),
]));

View File

@@ -1,5 +1,3 @@
#![allow(clippy::return_self_not_must_use)]
use std::convert::TryInto;
use std::ops::{Deref, Range};
use std::sync::Arc;
@@ -85,6 +83,7 @@ impl OwnedBytes {
/// Splits the right part of the `OwnedBytes` at the given offset.
///
/// `self` is truncated to `split_len`, left with the remaining bytes.
#[allow(clippy::return_self_not_must_use)]
pub fn split_off(&mut self, split_len: usize) -> OwnedBytes {
let right_box_stable_deref = self.box_stable_deref.clone();
let right_piece = OwnedBytes {

View File

@@ -250,7 +250,7 @@ mod tests {
// when harvesting we have to guarantee stable sorting in case of a tie
// on the score
let doc_ids_collection = [4, 5, 6];
let score = 3.14;
let score = 3.3f32;
let mut top_collector_limit_2 = TopSegmentCollector::new(0, 2);
for id in &doc_ids_collection {

View File

@@ -88,16 +88,21 @@ impl IndexBuilder {
index_settings: IndexSettings::default(),
}
}
/// Set the settings
#[must_use]
pub fn settings(mut self, settings: IndexSettings) -> Self {
self.index_settings = settings;
self
}
/// Set the schema
#[must_use]
pub fn schema(mut self, schema: Schema) -> Self {
self.schema = Some(schema);
self
}
/// Creates a new index using the `RAMDirectory`.
///
/// The index will be allocated in anonymous memory.
@@ -108,6 +113,7 @@ impl IndexBuilder {
.create(ram_directory)
.expect("Creating a RAMDirectory should never fail"))
}
/// Creates a new index in a given filepath.
/// The index will use the `MMapDirectory`.
///
@@ -120,6 +126,7 @@ impl IndexBuilder {
}
self.create(mmap_directory)
}
/// Creates a new index in a temp directory.
///
/// The index will use the `MMapDirectory` in a newly created directory.
@@ -133,12 +140,14 @@ impl IndexBuilder {
let mmap_directory: Box<dyn Directory> = Box::new(MmapDirectory::create_from_tempdir()?);
self.create(mmap_directory)
}
fn get_expect_schema(&self) -> crate::Result<Schema> {
self.schema
.as_ref()
.cloned()
.ok_or(TantivyError::IndexBuilderMissingArgument("schema"))
}
/// Opens or creates a new index in the provided directory
pub fn open_or_create<T: Into<Box<dyn Directory>>>(self, dir: T) -> crate::Result<Index> {
let dir = dir.into();

View File

@@ -192,6 +192,7 @@ impl SegmentMeta {
}
#[doc(hidden)]
#[must_use]
pub fn with_delete_meta(self, num_deleted_docs: u32, opstamp: Opstamp) -> SegmentMeta {
assert!(
num_deleted_docs <= self.max_doc(),

View File

@@ -54,6 +54,7 @@ impl Segment {
}
#[doc(hidden)]
#[must_use]
pub fn with_delete_meta(self, num_deleted_docs: u32, opstamp: Opstamp) -> Segment {
Segment {
index: self.index,

View File

@@ -77,6 +77,7 @@ impl FileSlice {
/// # Panics
///
/// Panics if `byte_range.end` exceeds the filesize.
#[must_use]
pub fn slice(&self, byte_range: Range<usize>) -> FileSlice {
assert!(byte_range.end <= self.len());
FileSlice {
@@ -136,6 +137,7 @@ impl FileSlice {
/// boundary.
///
/// Equivalent to `.slice(from_offset, self.len())`
#[must_use]
pub fn slice_from(&self, from_offset: usize) -> FileSlice {
self.slice(from_offset..self.len())
}
@@ -143,6 +145,7 @@ impl FileSlice {
/// Returns a slice from the end.
///
/// Equivalent to `.slice(self.len() - from_offset, self.len())`
#[must_use]
pub fn slice_from_end(&self, from_offset: usize) -> FileSlice {
self.slice(self.len() - from_offset..self.len())
}
@@ -151,6 +154,7 @@ impl FileSlice {
/// boundary.
///
/// Equivalent to `.slice(0, to_offset)`
#[must_use]
pub fn slice_to(&self, to_offset: usize) -> FileSlice {
self.slice(0..to_offset)
}

View File

@@ -514,7 +514,7 @@ mod tests {
{
for path in &paths {
let mut w = mmap_directory.open_write(path).unwrap();
w.write(content).unwrap();
w.write_all(content).unwrap();
w.flush().unwrap();
}
}

View File

@@ -79,7 +79,7 @@ mod tests {
fieldnorm_writers.record(3u32, *TXT_FIELD, 3);
fieldnorm_writers.serialize(serializer, None)?;
}
let file = directory.open_read(&path)?;
let file = directory.open_read(path)?;
{
let fields_composite = CompositeFile::open(&file)?;
assert!(fields_composite.open_read(*FIELD).is_none());

View File

@@ -272,7 +272,7 @@ mod tests {
let text_field = index.schema().get_field("text").unwrap();
let do_search = |term: &str| {
let query = QueryParser::for_index(&index, vec![text_field])
let query = QueryParser::for_index(index, vec![text_field])
.parse_query(term)
.unwrap();
let top_docs: Vec<(f32, DocAddress)> =
@@ -301,7 +301,7 @@ mod tests {
let text_field = index.schema().get_field("text").unwrap();
let do_search = |term: &str| {
let query = QueryParser::for_index(&index, vec![text_field])
let query = QueryParser::for_index(index, vec![text_field])
.parse_query(term)
.unwrap();
let top_docs: Vec<(f32, DocAddress)> =

View File

@@ -1081,7 +1081,7 @@ mod tests {
let target_schema = segments[0].schema();
let merged_index = Index::create(
RamDirectory::default(),
target_schema.clone(),
target_schema,
target_settings.clone(),
)?;
let merger: IndexMerger = IndexMerger::open_with_custom_alive_set(
@@ -1098,11 +1098,8 @@ mod tests {
{
let filter_segments = vec![None];
let target_schema = segments[0].schema();
let merged_index = Index::create(
RamDirectory::default(),
target_schema.clone(),
target_settings.clone(),
)?;
let merged_index =
Index::create(RamDirectory::default(), target_schema, target_settings)?;
let merger: IndexMerger = IndexMerger::open_with_custom_alive_set(
merged_index.schema(),
merged_index.settings().clone(),

View File

@@ -11,7 +11,6 @@
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
#![warn(missing_docs)]
#![allow(clippy::len_without_is_empty)]
#![allow(clippy::return_self_not_must_use)]
//! # `tantivy`
//!

View File

@@ -417,6 +417,7 @@ mod tests {
.boxed()
}
#[allow(clippy::type_complexity)]
fn gen_term_scorers(num_scorers: usize) -> BoxedStrategy<(Vec<Vec<(DocId, u32)>>, Vec<u32>)> {
(1u32..100u32)
.prop_flat_map(move |max_doc: u32| {

View File

@@ -67,6 +67,7 @@ impl MoreLikeThisQueryBuilder {
///
/// The resulting query will ignore words which do not occur
/// in at least this many docs.
#[must_use]
pub fn with_min_doc_frequency(mut self, value: u64) -> Self {
self.mlt.min_doc_frequency = Some(value);
self
@@ -76,6 +77,7 @@ impl MoreLikeThisQueryBuilder {
///
/// The resulting query will ignore words which occur
/// in more than this many docs.
#[must_use]
pub fn with_max_doc_frequency(mut self, value: u64) -> Self {
self.mlt.max_doc_frequency = Some(value);
self
@@ -85,6 +87,7 @@ impl MoreLikeThisQueryBuilder {
///
/// The resulting query will ignore words less
/// frequent that this number.
#[must_use]
pub fn with_min_term_frequency(mut self, value: usize) -> Self {
self.mlt.min_term_frequency = Some(value);
self
@@ -93,6 +96,7 @@ impl MoreLikeThisQueryBuilder {
/// Sets the maximum query terms.
///
/// The resulting query will not return a query with more clause than this.
#[must_use]
pub fn with_max_query_terms(mut self, value: usize) -> Self {
self.mlt.max_query_terms = Some(value);
self
@@ -101,6 +105,7 @@ impl MoreLikeThisQueryBuilder {
/// Sets the minimum word length.
///
/// The resulting query will ignore words shorter than this length.
#[must_use]
pub fn with_min_word_length(mut self, value: usize) -> Self {
self.mlt.min_word_length = Some(value);
self
@@ -109,6 +114,7 @@ impl MoreLikeThisQueryBuilder {
/// Sets the maximum word length.
///
/// The resulting query will ignore words longer than this length.
#[must_use]
pub fn with_max_word_length(mut self, value: usize) -> Self {
self.mlt.max_word_length = Some(value);
self
@@ -117,6 +123,7 @@ impl MoreLikeThisQueryBuilder {
/// Sets the boost factor
///
/// The boost factor used by the resulting query for boosting terms.
#[must_use]
pub fn with_boost_factor(mut self, value: f32) -> Self {
self.mlt.boost_factor = Some(value);
self
@@ -125,6 +132,7 @@ impl MoreLikeThisQueryBuilder {
/// Sets the set of stop words
///
/// The resulting query will ignore these set of words.
#[must_use]
pub fn with_stop_words(mut self, value: Vec<String>) -> Self {
self.mlt.stop_words = value;
self

View File

@@ -195,7 +195,7 @@ mod tests {
let searcher = index.reader()?.searcher();
{
let explanation = term_query.explain(&searcher, DocAddress::new(0u32, 1u32))?;
assert_nearly_equals!(explanation.value(), 0.6931472);
assert_nearly_equals!(explanation.value(), std::f32::consts::LN_2);
}
{
let explanation_err = term_query.explain(&searcher, DocAddress::new(0u32, 0u32));

View File

@@ -50,6 +50,7 @@ pub struct IndexReaderBuilder {
}
impl IndexReaderBuilder {
#[must_use]
pub(crate) fn new(index: Index) -> IndexReaderBuilder {
IndexReaderBuilder {
num_searchers: num_cpus::get(),
@@ -65,7 +66,6 @@ impl IndexReaderBuilder {
/// Building the reader is a non-trivial operation that requires
/// to open different segment readers. It may take hundreds of milliseconds
/// of time and it may return an error.
#[allow(clippy::needless_late_init)]
pub fn try_into(self) -> crate::Result<IndexReader> {
let searcher_generation_inventory = Inventory::default();
let warming_state = WarmingState::new(
@@ -83,11 +83,10 @@ impl IndexReaderBuilder {
};
inner_reader.reload()?;
let inner_reader_arc = Arc::new(inner_reader);
let watch_handle_opt: Option<WatchHandle>;
match self.reload_policy {
let watch_handle_opt: Option<WatchHandle> = match self.reload_policy {
ReloadPolicy::Manual => {
// No need to set anything...
watch_handle_opt = None;
None
}
ReloadPolicy::OnCommit => {
let inner_reader_arc_clone = inner_reader_arc.clone();
@@ -103,9 +102,9 @@ impl IndexReaderBuilder {
.index
.directory()
.watch(WatchCallback::new(callback))?;
watch_handle_opt = Some(watch_handle);
Some(watch_handle)
}
}
};
Ok(IndexReader {
inner: inner_reader_arc,
_watch_handle_opt: watch_handle_opt,
@@ -115,6 +114,7 @@ impl IndexReaderBuilder {
/// Sets the reload_policy.
///
/// See [`ReloadPolicy`](./enum.ReloadPolicy.html) for more details.
#[must_use]
pub fn reload_policy(mut self, reload_policy: ReloadPolicy) -> IndexReaderBuilder {
self.reload_policy = reload_policy;
self
@@ -123,12 +123,14 @@ impl IndexReaderBuilder {
/// Sets the number of [Searcher] to pool.
///
/// See [Self::searcher()].
#[must_use]
pub fn num_searchers(mut self, num_searchers: usize) -> IndexReaderBuilder {
self.num_searchers = num_searchers;
self
}
/// Set the [Warmer]s that are invoked when reloading searchable segments.
#[must_use]
pub fn warmers(mut self, warmers: Vec<Weak<dyn Warmer>>) -> IndexReaderBuilder {
self.warmers = warmers;
self
@@ -138,6 +140,7 @@ impl IndexReaderBuilder {
///
/// This allows parallelizing warming work when there are multiple [Warmer] registered with the
/// [IndexReader].
#[must_use]
pub fn num_warming_threads(mut self, num_warming_threads: usize) -> IndexReaderBuilder {
self.num_warming_threads = num_warming_threads;
self

View File

@@ -251,7 +251,7 @@ mod tests {
let schema = schema_builder.build();
let directory = RamDirectory::create();
let index = Index::create(directory.clone(), schema, IndexSettings::default())?;
let index = Index::create(directory, schema, IndexSettings::default())?;
let num_writer_threads = 4;
let mut writer = index

View File

@@ -63,6 +63,7 @@ impl BytesOptions {
///
/// Setting an integer as indexed will generate
/// a posting list for each value taken by the integer.
#[must_use]
pub fn set_indexed(mut self) -> BytesOptions {
self.indexed = true;
self
@@ -72,6 +73,7 @@ impl BytesOptions {
///
/// Setting an integer as normed will generate
/// the fieldnorm data for it.
#[must_use]
pub fn set_fieldnorms(mut self) -> BytesOptions {
self.fieldnorms = true;
self
@@ -83,6 +85,7 @@ impl BytesOptions {
/// Access time are similar to a random lookup in an array.
/// If more than one value is associated to a fast field, only the last one is
/// kept.
#[must_use]
pub fn set_fast(mut self) -> BytesOptions {
self.fast = true;
self
@@ -92,6 +95,7 @@ impl BytesOptions {
///
/// Only the fields that are set as *stored* are
/// persisted into the Tantivy's store.
#[must_use]
pub fn set_stored(mut self) -> BytesOptions {
self.stored = true;
self

View File

@@ -22,6 +22,7 @@ impl FacetOptions {
///
/// Only the fields that are set as *stored* are
/// persisted into the Tantivy's store.
#[must_use]
pub fn set_stored(mut self) -> FacetOptions {
self.stored = true;
self

View File

@@ -17,8 +17,7 @@ impl Field {
}
/// Returns a u32 identifying uniquely a field within a schema.
#[allow(clippy::trivially_copy_pass_by_ref)]
pub const fn field_id(&self) -> u32 {
pub const fn field_id(self) -> u32 {
self.0
}
}

View File

@@ -79,6 +79,7 @@ impl IntOptions {
///
/// Only the fields that are set as *stored* are
/// persisted into the Tantivy's store.
#[must_use]
pub fn set_stored(mut self) -> IntOptions {
self.stored = true;
self
@@ -90,6 +91,7 @@ impl IntOptions {
/// a posting list for each value taken by the integer.
///
/// This is required for the field to be searchable.
#[must_use]
pub fn set_indexed(mut self) -> IntOptions {
self.indexed = true;
self
@@ -99,6 +101,7 @@ impl IntOptions {
///
/// Setting an integer as fieldnorm will generate
/// the fieldnorm data for it.
#[must_use]
pub fn set_fieldnorm(mut self) -> IntOptions {
self.fieldnorms = true;
self
@@ -110,6 +113,7 @@ impl IntOptions {
/// Access time are similar to a random lookup in an array.
/// If more than one value is associated to a fast field, only the last one is
/// kept.
#[must_use]
pub fn set_fast(mut self, cardinality: Cardinality) -> IntOptions {
self.fast = Some(cardinality);
self

View File

@@ -25,12 +25,14 @@ impl TextOptions {
}
/// Sets the field as stored
#[must_use]
pub fn set_stored(mut self) -> TextOptions {
self.stored = true;
self
}
/// Sets the field as indexed, with the specific indexing options.
#[must_use]
pub fn set_indexing_options(mut self, indexing: TextFieldIndexing) -> TextOptions {
self.indexing = Some(indexing);
self
@@ -63,6 +65,7 @@ impl Default for TextFieldIndexing {
impl TextFieldIndexing {
/// Sets the tokenizer to be used for a given field.
#[must_use]
pub fn set_tokenizer(mut self, tokenizer_name: &str) -> TextFieldIndexing {
self.tokenizer = Cow::Owned(tokenizer_name.to_string());
self
@@ -74,6 +77,7 @@ impl TextFieldIndexing {
}
/// Sets fieldnorms
#[must_use]
pub fn set_fieldnorms(mut self, fieldnorms: bool) -> TextFieldIndexing {
self.fieldnorms = fieldnorms;
self
@@ -87,6 +91,7 @@ impl TextFieldIndexing {
/// Sets which information should be indexed with the tokens.
///
/// See [IndexRecordOption](./enum.IndexRecordOption.html) for more detail.
#[must_use]
pub fn set_index_option(mut self, index_option: IndexRecordOption) -> TextFieldIndexing {
self.record = index_option;
self

View File

@@ -78,6 +78,7 @@ impl TextAnalyzer {
/// .filter(LowerCaser)
/// .filter(Stemmer::default());
/// ```
#[must_use]
pub fn filter<F: Into<BoxTokenFilter>>(mut self, token_filter: F) -> Self {
self.token_filters.push(token_filter.into());
self