Skip to content

Commit 74275b7

Browse files
authored
Inline format arguments where makes sense (#2038)
Applied this command to the code, making it a bit shorter and slightly more readable. ``` cargo +nightly clippy --all-features --benches --tests --workspace --fix -- -A clippy::all -W clippy::uninlined_format_args cargo +nightly fmt --all ```
1 parent f479840 commit 74275b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+170
-224
lines changed

columnar/src/columnar/column_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl fmt::Display for ColumnType {
3434
ColumnType::IpAddr => "ip",
3535
ColumnType::DateTime => "datetime",
3636
};
37-
write!(f, "{}", short_str)
37+
write!(f, "{short_str}")
3838
}
3939
}
4040

columnar/src/dynamic_column.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ impl fmt::Debug for DynamicColumn {
2626
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2727
write!(f, "[{} {} |", self.get_cardinality(), self.column_type())?;
2828
match self {
29-
DynamicColumn::Bool(col) => write!(f, " {:?}", col)?,
30-
DynamicColumn::I64(col) => write!(f, " {:?}", col)?,
31-
DynamicColumn::U64(col) => write!(f, " {:?}", col)?,
32-
DynamicColumn::F64(col) => write!(f, "{:?}", col)?,
33-
DynamicColumn::IpAddr(col) => write!(f, "{:?}", col)?,
34-
DynamicColumn::DateTime(col) => write!(f, "{:?}", col)?,
35-
DynamicColumn::Bytes(col) => write!(f, "{:?}", col)?,
36-
DynamicColumn::Str(col) => write!(f, "{:?}", col)?,
29+
DynamicColumn::Bool(col) => write!(f, " {col:?}")?,
30+
DynamicColumn::I64(col) => write!(f, " {col:?}")?,
31+
DynamicColumn::U64(col) => write!(f, " {col:?}")?,
32+
DynamicColumn::F64(col) => write!(f, "{col:?}")?,
33+
DynamicColumn::IpAddr(col) => write!(f, "{col:?}")?,
34+
DynamicColumn::DateTime(col) => write!(f, "{col:?}")?,
35+
DynamicColumn::Bytes(col) => write!(f, "{col:?}")?,
36+
DynamicColumn::Str(col) => write!(f, "{col:?}")?,
3737
}
3838
write!(f, "]")
3939
}

common/src/byte_count.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl ByteCount {
3737
for (suffix, threshold) in SUFFIX_AND_THRESHOLD.iter().rev() {
3838
if self.get_bytes() >= *threshold {
3939
let unit_num = self.get_bytes() as f64 / *threshold as f64;
40-
return format!("{:.2} {}", unit_num, suffix);
40+
return format!("{unit_num:.2} {suffix}");
4141
}
4242
}
4343
format!("{:.2} B", self.get_bytes())

common/src/vint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ mod tests {
261261
let mut buffer2 = [0u8; 8];
262262
let len_vint = VInt(val as u64).serialize_into(&mut buffer);
263263
let res2 = serialize_vint_u32(val, &mut buffer2);
264-
assert_eq!(&buffer[..len_vint], res2, "array wrong for {}", val);
264+
assert_eq!(&buffer[..len_vint], res2, "array wrong for {val}");
265265
}
266266

267267
#[test]

examples/index_from_multiple_threads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn main() -> tantivy::Result<()> {
9696
let mut index_writer_wlock = index_writer.write().unwrap();
9797
index_writer_wlock.commit()?
9898
};
99-
println!("committed with opstamp {}", opstamp);
99+
println!("committed with opstamp {opstamp}");
100100
thread::sleep(Duration::from_millis(500));
101101
}
102102

examples/iterating_docs_and_positions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn main() -> tantivy::Result<()> {
8484
// Doc 0: TermFreq 2: [0, 4]
8585
// Doc 2: TermFreq 1: [0]
8686
// ```
87-
println!("Doc {}: TermFreq {}: {:?}", doc_id, term_freq, positions);
87+
println!("Doc {doc_id}: TermFreq {term_freq}: {positions:?}");
8888
doc_id = segment_postings.advance();
8989
}
9090
}
@@ -125,7 +125,7 @@ fn main() -> tantivy::Result<()> {
125125
// Once again these docs MAY contains deleted documents as well.
126126
let docs = block_segment_postings.docs();
127127
// Prints `Docs [0, 2].`
128-
println!("Docs {:?}", docs);
128+
println!("Docs {docs:?}");
129129
block_segment_postings.advance();
130130
}
131131
}

examples/snippet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn main() -> tantivy::Result<()> {
5656
for (score, doc_address) in top_docs {
5757
let doc = searcher.doc(doc_address)?;
5858
let snippet = snippet_generator.snippet_from_doc(&doc);
59-
println!("Document score {}:", score);
59+
println!("Document score {score}:");
6060
println!(
6161
"title: {}",
6262
doc.get_first(title).unwrap().as_text().unwrap()

examples/stop_words.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn main() -> tantivy::Result<()> {
106106

107107
for (score, doc_address) in top_docs {
108108
let retrieved_doc = searcher.doc(doc_address)?;
109-
println!("\n==\nDocument score {}:", score);
109+
println!("\n==\nDocument score {score}:");
110110
println!("{}", schema.to_json(&retrieved_doc));
111111
}
112112

ownedbytes/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl fmt::Debug for OwnedBytes {
160160
} else {
161161
self.as_slice()
162162
};
163-
write!(f, "OwnedBytes({:?}, len={})", bytes_truncated, self.len())
163+
write!(f, "OwnedBytes({bytes_truncated:?}, len={})", self.len())
164164
}
165165
}
166166

@@ -259,12 +259,12 @@ mod tests {
259259
fn test_owned_bytes_debug() {
260260
let short_bytes = OwnedBytes::new(b"abcd".as_ref());
261261
assert_eq!(
262-
format!("{:?}", short_bytes),
262+
format!("{short_bytes:?}"),
263263
"OwnedBytes([97, 98, 99, 100], len=4)"
264264
);
265265
let long_bytes = OwnedBytes::new(b"abcdefghijklmnopq".as_ref());
266266
assert_eq!(
267-
format!("{:?}", long_bytes),
267+
format!("{long_bytes:?}"),
268268
"OwnedBytes([97, 98, 99, 100, 101, 102, 103, 104, 105, 106], len=17)"
269269
);
270270
}

query-grammar/src/query_grammar.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn word<'a>() -> impl Parser<&'a str, Output = String> {
5656
!c.is_whitespace() && ![':', '^', '{', '}', '"', '[', ']', '(', ')'].contains(&c)
5757
})),
5858
)
59-
.map(|(s1, s2): (char, String)| format!("{}{}", s1, s2))
59+
.map(|(s1, s2): (char, String)| format!("{s1}{s2}"))
6060
.and_then(|s: String| match s.as_str() {
6161
"OR" | "AND " | "NOT" => Err(StringStreamError::UnexpectedParse),
6262
_ => Ok(s),
@@ -74,7 +74,7 @@ fn relaxed_word<'a>() -> impl Parser<&'a str, Output = String> {
7474
!c.is_whitespace() && !['{', '}', '"', '[', ']', '(', ')'].contains(&c)
7575
})),
7676
)
77-
.map(|(s1, s2): (char, String)| format!("{}{}", s1, s2))
77+
.map(|(s1, s2): (char, String)| format!("{s1}{s2}"))
7878
}
7979

8080
/// Parses a date time according to rfc3339
@@ -178,9 +178,9 @@ fn negative_number<'a>() -> impl Parser<&'a str, Output = String> {
178178
)
179179
.map(|(s1, s2, s3): (char, String, Option<(char, String)>)| {
180180
if let Some(('.', s3)) = s3 {
181-
format!("{}{}.{}", s1, s2, s3)
181+
format!("{s1}{s2}.{s3}")
182182
} else {
183-
format!("{}{}", s1, s2)
183+
format!("{s1}{s2}")
184184
}
185185
})
186186
}
@@ -419,9 +419,7 @@ mod test {
419419
fn assert_nearly_equals(expected: f64, val: f64) {
420420
assert!(
421421
nearly_equals(val, expected),
422-
"Got {}, expected {}.",
423-
val,
424-
expected
422+
"Got {val}, expected {expected}."
425423
);
426424
}
427425

@@ -468,7 +466,7 @@ mod test {
468466

469467
fn test_parse_query_to_ast_helper(query: &str, expected: &str) {
470468
let query = parse_to_ast().parse(query).unwrap().0;
471-
let query_str = format!("{:?}", query);
469+
let query_str = format!("{query:?}");
472470
assert_eq!(query_str, expected);
473471
}
474472

@@ -554,7 +552,7 @@ mod test {
554552
fn test_occur_leaf() {
555553
let ((occur, ast), _) = super::occur_leaf().parse("+abc").unwrap();
556554
assert_eq!(occur, Some(Occur::Must));
557-
assert_eq!(format!("{:?}", ast), "\"abc\"");
555+
assert_eq!(format!("{ast:?}"), "\"abc\"");
558556
}
559557

560558
#[test]
@@ -613,7 +611,7 @@ mod test {
613611
let escaped_special_chars_re = Regex::new(ESCAPED_SPECIAL_CHARS_PATTERN).unwrap();
614612
for special_char in SPECIAL_CHARS.iter() {
615613
assert_eq!(
616-
escaped_special_chars_re.replace_all(&format!("\\{}", special_char), "$1"),
614+
escaped_special_chars_re.replace_all(&format!("\\{special_char}"), "$1"),
617615
special_char.to_string()
618616
);
619617
}

query-grammar/src/user_input_ast.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Debug for UserInputLeaf {
2828
ref upper,
2929
} => {
3030
if let Some(ref field) = field {
31-
write!(formatter, "\"{}\":", field)?;
31+
write!(formatter, "\"{field}\":")?;
3232
}
3333
lower.display_lower(formatter)?;
3434
write!(formatter, " TO ")?;
@@ -37,14 +37,14 @@ impl Debug for UserInputLeaf {
3737
}
3838
UserInputLeaf::Set { field, elements } => {
3939
if let Some(ref field) = field {
40-
write!(formatter, "\"{}\": ", field)?;
40+
write!(formatter, "\"{field}\": ")?;
4141
}
4242
write!(formatter, "IN [")?;
4343
for (i, element) in elements.iter().enumerate() {
4444
if i != 0 {
4545
write!(formatter, " ")?;
4646
}
47-
write!(formatter, "\"{}\"", element)?;
47+
write!(formatter, "\"{element}\"")?;
4848
}
4949
write!(formatter, "]")
5050
}
@@ -63,7 +63,7 @@ pub struct UserInputLiteral {
6363
impl fmt::Debug for UserInputLiteral {
6464
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
6565
if let Some(ref field) = self.field_name {
66-
write!(formatter, "\"{}\":", field)?;
66+
write!(formatter, "\"{field}\":")?;
6767
}
6868
write!(formatter, "\"{}\"", self.phrase)?;
6969
if self.slop > 0 {
@@ -83,16 +83,16 @@ pub enum UserInputBound {
8383
impl UserInputBound {
8484
fn display_lower(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
8585
match *self {
86-
UserInputBound::Inclusive(ref word) => write!(formatter, "[\"{}\"", word),
87-
UserInputBound::Exclusive(ref word) => write!(formatter, "{{\"{}\"", word),
86+
UserInputBound::Inclusive(ref word) => write!(formatter, "[\"{word}\""),
87+
UserInputBound::Exclusive(ref word) => write!(formatter, "{{\"{word}\""),
8888
UserInputBound::Unbounded => write!(formatter, "{{\"*\""),
8989
}
9090
}
9191

9292
fn display_upper(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
9393
match *self {
94-
UserInputBound::Inclusive(ref word) => write!(formatter, "\"{}\"]", word),
95-
UserInputBound::Exclusive(ref word) => write!(formatter, "\"{}\"}}", word),
94+
UserInputBound::Inclusive(ref word) => write!(formatter, "\"{word}\"]"),
95+
UserInputBound::Exclusive(ref word) => write!(formatter, "\"{word}\"}}"),
9696
UserInputBound::Unbounded => write!(formatter, "\"*\"}}"),
9797
}
9898
}
@@ -163,9 +163,9 @@ fn print_occur_ast(
163163
formatter: &mut fmt::Formatter,
164164
) -> fmt::Result {
165165
if let Some(occur) = occur_opt {
166-
write!(formatter, "{}{:?}", occur, ast)?;
166+
write!(formatter, "{occur}{ast:?}")?;
167167
} else {
168-
write!(formatter, "*{:?}", ast)?;
168+
write!(formatter, "*{ast:?}")?;
169169
}
170170
Ok(())
171171
}
@@ -187,8 +187,8 @@ impl fmt::Debug for UserInputAst {
187187
}
188188
Ok(())
189189
}
190-
UserInputAst::Leaf(ref subquery) => write!(formatter, "{:?}", subquery),
191-
UserInputAst::Boost(ref leaf, boost) => write!(formatter, "({:?})^{}", leaf, boost),
190+
UserInputAst::Leaf(ref subquery) => write!(formatter, "{subquery:?}"),
191+
UserInputAst::Boost(ref leaf, boost) => write!(formatter, "({leaf:?})^{boost}"),
192192
}
193193
}
194194
}

src/aggregation/agg_result.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ impl AggregationResults {
3434
} else {
3535
// Validation is be done during request parsing, so we can't reach this state.
3636
Err(TantivyError::InternalError(format!(
37-
"Can't find aggregation {:?} in sub-aggregations",
38-
name
37+
"Can't find aggregation {name:?} in sub-aggregations"
3938
)))
4039
}
4140
}

src/aggregation/agg_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ fn test_aggregation_invalid_requests() -> crate::Result<()> {
533533

534534
let agg_res = avg_on_field("dummy_text").unwrap_err();
535535
assert_eq!(
536-
format!("{:?}", agg_res),
536+
format!("{agg_res:?}"),
537537
r#"InvalidArgument("Field \"dummy_text\" is not configured as fast field")"#
538538
);
539539

src/aggregation/bucket/histogram/date_histogram.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,14 @@ impl DateHistogramAggregationReq {
131131
fn validate(&self) -> crate::Result<()> {
132132
if let Some(interval) = self.interval.as_ref() {
133133
return Err(crate::TantivyError::InvalidArgument(format!(
134-
"`interval` parameter {:?} in date histogram is unsupported, only \
135-
`fixed_interval` is supported",
136-
interval
134+
"`interval` parameter {interval:?} in date histogram is unsupported, only \
135+
`fixed_interval` is supported"
137136
)));
138137
}
139138
if let Some(interval) = self.calendar_interval.as_ref() {
140139
return Err(crate::TantivyError::InvalidArgument(format!(
141-
"`calendar_interval` parameter {:?} in date histogram is unsupported, only \
142-
`fixed_interval` is supported",
143-
interval
140+
"`calendar_interval` parameter {interval:?} in date histogram is unsupported, \
141+
only `fixed_interval` is supported"
144142
)));
145143
}
146144
if self.format.is_some() {

src/aggregation/bucket/histogram/histogram.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ impl HistogramAggregation {
142142
{
143143
if extended_bounds.min < hard_bounds.min || extended_bounds.max > hard_bounds.max {
144144
return Err(TantivyError::InvalidArgument(format!(
145-
"extended_bounds have to be inside hard_bounds, extended_bounds: {}, \
146-
hard_bounds {}",
147-
extended_bounds, hard_bounds
145+
"extended_bounds have to be inside hard_bounds, extended_bounds: \
146+
{extended_bounds}, hard_bounds {hard_bounds}"
148147
)));
149148
}
150149
}

src/aggregation/bucket/term_agg.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ impl SegmentTermCollector {
333333

334334
sub_aggregations.aggs.get(agg_name).ok_or_else(|| {
335335
TantivyError::InvalidArgument(format!(
336-
"could not find aggregation with name {} in metric sub_aggregations",
337-
agg_name
336+
"could not find aggregation with name {agg_name} in metric \
337+
sub_aggregations"
338338
))
339339
})?;
340340
}
@@ -409,10 +409,7 @@ impl SegmentTermCollector {
409409
.sub_aggs
410410
.remove(&id)
411411
.unwrap_or_else(|| {
412-
panic!(
413-
"Internal Error: could not find subaggregation for id {}",
414-
id
415-
)
412+
panic!("Internal Error: could not find subaggregation for id {id}")
416413
})
417414
.add_intermediate_aggregation_result(
418415
&agg_with_accessor.sub_aggregation,
@@ -442,8 +439,7 @@ impl SegmentTermCollector {
442439
for (term_id, doc_count) in entries {
443440
if !term_dict.ord_to_str(term_id, &mut buffer)? {
444441
return Err(TantivyError::InternalError(format!(
445-
"Couldn't find term_id {} in dict",
446-
term_id
442+
"Couldn't find term_id {term_id} in dict"
447443
)));
448444
}
449445

src/aggregation/date.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use crate::TantivyError;
66
pub(crate) fn format_date(val: i64) -> crate::Result<String> {
77
let datetime = OffsetDateTime::from_unix_timestamp_nanos(val as i128).map_err(|err| {
88
TantivyError::InvalidArgument(format!(
9-
"Could not convert {:?} to OffsetDateTime, err {:?}",
10-
val, err
9+
"Could not convert {val:?} to OffsetDateTime, err {err:?}"
1110
))
1211
})?;
1312
let key_as_string = datetime

src/aggregation/metric/percentiles.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ impl PercentilesCollector {
213213
pub(crate) fn merge_fruits(&mut self, right: PercentilesCollector) -> crate::Result<()> {
214214
self.sketch.merge(&right.sketch).map_err(|err| {
215215
TantivyError::AggregationError(AggregationError::InternalError(format!(
216-
"Error while merging percentiles {:?}",
217-
err
216+
"Error while merging percentiles {err:?}"
218217
)))
219218
})?;
220219

src/aggregation/metric/stats.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ impl Stats {
6666
"max" => Ok(self.max),
6767
"avg" => Ok(self.avg),
6868
_ => Err(TantivyError::InvalidArgument(format!(
69-
"Unknown property {} on stats metric aggregation",
70-
agg_property
69+
"Unknown property {agg_property} on stats metric aggregation"
7170
))),
7271
}
7372
}

src/aggregation/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ pub(crate) fn f64_from_fastfield_u64(val: u64, field_type: &ColumnType) -> f64 {
292292
ColumnType::I64 | ColumnType::DateTime => i64::from_u64(val) as f64,
293293
ColumnType::F64 => f64::from_u64(val),
294294
_ => {
295-
panic!("unexpected type {:?}. This should not happen", field_type)
295+
panic!("unexpected type {field_type:?}. This should not happen")
296296
}
297297
}
298298
}

src/collector/facet_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ mod bench {
812812

813813
let mut docs = vec![];
814814
for val in 0..50 {
815-
let facet = Facet::from(&format!("/facet_{}", val));
815+
let facet = Facet::from(&format!("/facet_{val}"));
816816
for _ in 0..val * val {
817817
docs.push(doc!(facet_field=>facet.clone()));
818818
}

0 commit comments

Comments
 (0)