Skip to content

Commit 8caf7fa

Browse files
authored
chore: Apply clippy lints from 1.59.0 (#11595)
Signed-off-by: Jesse Szwedko <[email protected]>
1 parent 762a5e6 commit 8caf7fa

File tree

55 files changed

+115
-107
lines changed

Some content is hidden

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

55 files changed

+115
-107
lines changed

lib/datadog/grok/src/matchers/date.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,12 @@ fn parse_tz_id_or_name(tz: &str) -> Result<FixedOffset, String> {
108108
}
109109

110110
fn parse_offset(tz: &str) -> Result<FixedOffset, String> {
111-
let offset_format;
112111
if tz.len() <= 3 {
113112
// +5, -12
114113
let hours_diff = tz.parse::<i32>().map_err(|e| e.to_string())?;
115114
return Ok(FixedOffset::east(hours_diff * 3600));
116115
}
117-
if tz.contains(':') {
118-
offset_format = "%:z";
119-
} else {
120-
offset_format = "%z";
121-
}
116+
let offset_format = if tz.contains(':') { "%:z" } else { "%z" };
122117
// apparently the easiest way to parse tz offset is parsing the complete datetime
123118
let date_str = format!("2020-04-12 22:10:57 {}", tz);
124119
let datetime =

lib/datadog/search-syntax/src/field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn normalize_fields<T: AsRef<str>>(value: T) -> Vec<Field> {
5959
.collect();
6060
}
6161

62-
let field = match value.replace("@", "custom.") {
62+
let field = match value.replace('@', "custom.") {
6363
v if value.starts_with('@') => Field::Facet(v),
6464
v if DEFAULT_FIELDS.contains(&v.as_ref()) => Field::Default(v),
6565
v if RESERVED_ATTRIBUTES.contains(&v.as_ref()) => Field::Reserved(v),

lib/dnsmsg-parser/src/dns_message_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ fn parse_character_string(decoder: &mut BinDecoder<'_>) -> DnsParserResult<Strin
10331033
"Unexpected data length: expected {}, got {}. Raw data {}",
10341034
len,
10351035
raw_data.len(),
1036-
format_bytes_as_hex_string(&raw_data.to_vec())
1036+
format_bytes_as_hex_string(raw_data)
10371037
),
10381038
}),
10391039
}
@@ -1106,7 +1106,7 @@ fn parse_domain_name(decoder: &mut BinDecoder<'_>) -> DnsParserResult<Name> {
11061106
}
11071107

11081108
fn escape_string_for_text_representation(original_string: String) -> String {
1109-
original_string.replace("\\", "\\\\").replace("\"", "\\\"")
1109+
original_string.replace('\\', "\\\\").replace('\"', "\\\"")
11101110
}
11111111

11121112
fn parse_unknown_record_type(rtype: u16) -> Option<String> {

lib/file-source/src/fingerprinter.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,7 @@ mod test {
455455
let mut buf = Vec::new();
456456
let mut small_files = HashSet::new();
457457
assert!(fingerprinter
458-
.get_fingerprint_or_log_error(
459-
&target_dir.path().to_owned(),
460-
&mut buf,
461-
&mut small_files,
462-
&NoErrors
463-
)
458+
.get_fingerprint_or_log_error(target_dir.path(), &mut buf, &mut small_files, &NoErrors)
464459
.is_none());
465460
}
466461

lib/file-source/src/paths_provider/glob.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ impl<E: FileSourceInternalEvents> Glob<E> {
3636

3737
let exclude_patterns = exclude_patterns
3838
.iter()
39-
.map(|path| path.to_str().map(|path| Pattern::new(path).ok()))
40-
.flatten()
39+
.filter_map(|path| path.to_str().map(|path| Pattern::new(path).ok()))
4140
.collect::<Option<Vec<_>>>()?;
4241

4342
Some(Self {

lib/k8s-e2e-tests/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn get_override_name(namespace: &str, suffix: &str) -> String {
4545

4646
/// Is the MULTINODE environment variable set?
4747
pub fn is_multinode() -> bool {
48-
env::var("MULTINODE".to_string()).is_ok()
48+
env::var("MULTINODE").is_ok()
4949
}
5050

5151
/// Create config adding fullnameOverride entry. This allows multiple tests

lib/k8s-test-framework/src/kubernetes_version.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ pub async fn get(kubectl_command: &str) -> Result<K8sVersion> {
2323
let json: serde_json::Value = serde_json::from_slice(&reader.stdout)?;
2424

2525
Ok(K8sVersion {
26-
major: json["serverVersion"]["major"].to_string().replace("\"", ""),
27-
minor: json["serverVersion"]["minor"].to_string().replace("\"", ""),
26+
major: json["serverVersion"]["major"].to_string().replace('\"', ""),
27+
minor: json["serverVersion"]["minor"].to_string().replace('\"', ""),
2828
platform: json["serverVersion"]["platform"]
2929
.to_string()
30-
.replace("\"", ""),
30+
.replace('\"', ""),
3131
git_version: json["serverVersion"]["gitVersion"]
3232
.to_string()
33-
.replace("\"", ""),
33+
.replace('\"', ""),
3434
})
3535
}
3636

lib/lookup/src/lookup_buf/segmentbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Arbitrary for FieldBuf {
6464
let name = (0..len)
6565
.map(|_| chars[usize::arbitrary(g) % chars.len()])
6666
.collect::<String>()
67-
.replace(r#"""#, r#"\""#);
67+
.replace('"', r#"\""#);
6868
FieldBuf::from(name)
6969
}
7070

@@ -74,7 +74,7 @@ impl Arbitrary for FieldBuf {
7474
.shrink()
7575
.filter(|name| !name.is_empty())
7676
.map(|name| {
77-
let name = name.replace(r#"""#, r#"/""#);
77+
let name = name.replace('"', r#"/""#);
7878
FieldBuf::from(name)
7979
}),
8080
)

lib/value/src/value/api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::use_self)] // I don't think Self can be used here, it creates a cycle
2+
13
use async_graphql::scalar;
24

35
use crate::value::Value;

lib/value/src/value/display.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ impl fmt::Display for Value {
99
f,
1010
r#""{}""#,
1111
String::from_utf8_lossy(val)
12-
.replace(r#"\"#, r#"\\"#)
13-
.replace(r#"""#, r#"\""#)
14-
.replace("\n", r#"\n"#)
12+
.replace('\\', r#"\\"#)
13+
.replace('"', r#"\""#)
14+
.replace('\n', r#"\n"#)
1515
),
1616
Value::Integer(val) => write!(f, "{}", val),
1717
Value::Float(val) => write!(f, "{}", val),

lib/value/src/value/path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ impl Value {
77
///
88
/// For example, given the path `.foo.bar` and value `true`, the return
99
/// value would be an object representing `{ "foo": { "bar": true } }`.
10+
#[must_use]
1011
pub fn at_path(mut self, path: &LookupBuf) -> Self {
1112
for segment in path.as_segments().iter().rev() {
1213
match segment {

lib/vector-buffers/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl BufferConfig {
335335
{
336336
let mut builder = TopologyBuilder::default();
337337

338-
for stage in self.stages.iter().copied() {
338+
for stage in &self.stages {
339339
stage.add_to_builder(&mut builder, data_dir.clone(), buffer_id.clone())?;
340340
}
341341

lib/vector-core/src/config/id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl ComponentKey {
1818
&self.id
1919
}
2020

21+
#[must_use]
2122
pub fn join<D: fmt::Display>(&self, name: D) -> Self {
2223
Self {
2324
id: format!("{}.{}", self.id, name),

lib/vector-core/src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl Output {
119119
}
120120

121121
/// Set the schema definition for this output.
122+
#[must_use]
122123
pub fn with_schema_definition(mut self, schema_definition: schema::Definition) -> Self {
123124
self.log_schema_definition = Some(schema_definition);
124125
self
@@ -141,6 +142,7 @@ pub struct AcknowledgementsConfig {
141142
}
142143

143144
impl AcknowledgementsConfig {
145+
#[must_use]
144146
pub fn merge_default(&self, other: &Self) -> Self {
145147
let enabled = self.enabled.or(other.enabled);
146148
Self { enabled }

lib/vector-core/src/config/proxy.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl ProxyConfig {
8989
// overrides current proxy configuration with other configuration
9090
// if `self` is the global config and `other` the component config,
9191
// if both have the `http` proxy set, the one from `other` should be kept
92+
#[must_use]
9293
pub fn merge(&self, other: &Self) -> Self {
9394
let no_proxy = if other.no_proxy.is_empty() {
9495
self.no_proxy.clone()
@@ -188,7 +189,7 @@ mod tests {
188189
let result = first.merge(&second).merge(&third);
189190
assert_eq!(result.http, Some("http://1.2.3.4:5678".into()));
190191
assert_eq!(result.https, Some("https://2.3.4.5:9876".into()));
191-
assert!(result.no_proxy.matches(&"localhost".to_string()));
192+
assert!(result.no_proxy.matches("localhost"));
192193
}
193194

194195
#[test]
@@ -207,8 +208,8 @@ mod tests {
207208
let result = first.merge(&second);
208209
assert_eq!(result.http, Some("http://1.2.3.4:5678".into()));
209210
assert_eq!(result.https, Some("https://2.3.4.5:9876".into()));
210-
assert!(!result.no_proxy.matches(&"127.0.0.1".to_string()));
211-
assert!(result.no_proxy.matches(&"localhost".to_string()));
211+
assert!(!result.no_proxy.matches("127.0.0.1"));
212+
assert!(result.no_proxy.matches("localhost"));
212213
}
213214

214215
#[test]

lib/vector-core/src/event/finalization.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ impl EventStatus {
309309
/// Passing a new status of `Dropped` is a programming error and
310310
/// will panic in debug/test builds.
311311
#[allow(clippy::match_same_arms)] // False positive: https://github.com/rust-lang/rust-clippy/issues/860
312+
#[must_use]
312313
pub fn update(self, status: Self) -> Self {
313314
match (self, status) {
314315
// `Recorded` always overwrites existing status and is never updated

lib/vector-core/src/event/log_event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ impl LogEvent {
9595
)
9696
}
9797

98+
#[must_use]
9899
pub fn with_batch_notifier(mut self, batch: &Arc<BatchNotifier>) -> Self {
99100
self.metadata = self.metadata.with_batch_notifier(batch);
100101
self
101102
}
102103

104+
#[must_use]
103105
pub fn with_batch_notifier_option(mut self, batch: &Option<Arc<BatchNotifier>>) -> Self {
104106
self.metadata = self.metadata.with_batch_notifier_option(batch);
105107
self

lib/vector-core/src/event/metadata.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,20 @@ impl ByteSizeOf for EventMetadata {
7777

7878
impl EventMetadata {
7979
/// Replace the finalizers array with the given one.
80+
#[must_use]
8081
pub fn with_finalizer(mut self, finalizer: EventFinalizer) -> Self {
8182
self.finalizers = EventFinalizers::new(finalizer);
8283
self
8384
}
8485

8586
/// Replace the finalizer with a new one created from the given batch notifier.
87+
#[must_use]
8688
pub fn with_batch_notifier(self, batch: &Arc<BatchNotifier>) -> Self {
8789
self.with_finalizer(EventFinalizer::new(Arc::clone(batch)))
8890
}
8991

9092
/// Replace the finalizer with a new one created from the given optional batch notifier.
93+
#[must_use]
9194
pub fn with_batch_notifier_option(self, batch: &Option<Arc<BatchNotifier>>) -> Self {
9295
match batch {
9396
Some(batch) => self.with_finalizer(EventFinalizer::new(Arc::clone(batch))),
@@ -96,6 +99,7 @@ impl EventMetadata {
9699
}
97100

98101
/// Replace the schema definition with the given one.
102+
#[must_use]
99103
pub fn with_schema_definition(mut self, schema_definition: &Arc<schema::Definition>) -> Self {
100104
self.schema_definition = Arc::clone(schema_definition);
101105
self

lib/vector-core/src/event/metric.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,18 +589,21 @@ impl Metric {
589589
}
590590

591591
#[inline]
592+
#[must_use]
592593
pub fn with_name(mut self, name: impl Into<String>) -> Self {
593594
self.series.name.name = name.into();
594595
self
595596
}
596597

597598
#[inline]
599+
#[must_use]
598600
pub fn with_namespace<T: Into<String>>(mut self, namespace: Option<T>) -> Self {
599601
self.series.name.namespace = namespace.map(Into::into);
600602
self
601603
}
602604

603605
#[inline]
606+
#[must_use]
604607
pub fn with_timestamp(mut self, timestamp: Option<DateTime<Utc>>) -> Self {
605608
self.data.timestamp = timestamp;
606609
self
@@ -610,23 +613,27 @@ impl Metric {
610613
self.metadata.add_finalizer(finalizer);
611614
}
612615

616+
#[must_use]
613617
pub fn with_batch_notifier(mut self, batch: &Arc<BatchNotifier>) -> Self {
614618
self.metadata = self.metadata.with_batch_notifier(batch);
615619
self
616620
}
617621

622+
#[must_use]
618623
pub fn with_batch_notifier_option(mut self, batch: &Option<Arc<BatchNotifier>>) -> Self {
619624
self.metadata = self.metadata.with_batch_notifier_option(batch);
620625
self
621626
}
622627

623628
#[inline]
629+
#[must_use]
624630
pub fn with_tags(mut self, tags: Option<MetricTags>) -> Self {
625631
self.series.tags = tags;
626632
self
627633
}
628634

629635
#[inline]
636+
#[must_use]
630637
pub fn with_value(mut self, value: MetricValue) -> Self {
631638
self.data.value = value;
632639
self
@@ -647,6 +654,7 @@ impl Metric {
647654
}
648655

649656
/// Rewrite this into a Metric with the data marked as absolute.
657+
#[must_use]
650658
pub fn into_absolute(self) -> Self {
651659
Self {
652660
series: self.series,
@@ -656,6 +664,7 @@ impl Metric {
656664
}
657665

658666
/// Rewrite this into a Metric with the data marked as incremental.
667+
#[must_use]
659668
pub fn into_incremental(self) -> Self {
660669
Self {
661670
series: self.series,
@@ -840,6 +849,7 @@ impl MetricSeries {
840849

841850
impl MetricData {
842851
/// Rewrite this data to mark it as absolute.
852+
#[must_use]
843853
pub fn into_absolute(self) -> Self {
844854
Self {
845855
timestamp: self.timestamp,
@@ -849,6 +859,7 @@ impl MetricData {
849859
}
850860

851861
/// Rewrite this data to mark it as incremental.
862+
#[must_use]
852863
pub fn into_incremental(self) -> Self {
853864
Self {
854865
timestamp: self.timestamp,

lib/vector-core/src/event/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ impl Event {
256256
}
257257
}
258258

259+
#[must_use]
259260
pub fn with_batch_notifier(self, batch: &Arc<BatchNotifier>) -> Self {
260261
match self {
261262
Self::Log(log) => log.with_batch_notifier(batch).into(),
@@ -264,6 +265,7 @@ impl Event {
264265
}
265266
}
266267

268+
#[must_use]
267269
pub fn with_batch_notifier_option(self, batch: &Option<Arc<BatchNotifier>>) -> Self {
268270
match self {
269271
Self::Log(log) => log.with_batch_notifier_option(batch).into(),

lib/vector-core/src/event/proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl From<sketch::AgentDdSketch> for MetricSketch {
383383
.map(|k| (k, k > 0))
384384
.map(|(k, pos)| {
385385
k.try_into()
386-
.unwrap_or_else(|_| if pos { i16::MAX } else { i16::MIN })
386+
.unwrap_or(if pos { i16::MAX } else { i16::MIN })
387387
})
388388
.collect::<Vec<_>>();
389389
let counts = sketch

lib/vector-core/src/event/util/log/all_fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a> FieldsIter<'a> {
7575
None => return res,
7676
Some(PathComponent::Key(key)) => {
7777
if key.contains('.') {
78-
res.push_str(&key.replace(".", "\\."));
78+
res.push_str(&key.replace('.', "\\."));
7979
} else {
8080
res.push_str(key);
8181
}

0 commit comments

Comments
 (0)