Skip to content

Commit c647690

Browse files
committed
chore: Apply clippy lints from 1.59.0
Signed-off-by: Jesse Szwedko <[email protected]>
1 parent 89aa5f9 commit c647690

File tree

55 files changed

+114
-100
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

+114
-100
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ mod test {
456456
let mut small_files = HashSet::new();
457457
assert!(fingerprinter
458458
.get_fingerprint_or_log_error(
459-
&target_dir.path().to_owned(),
459+
target_dir.path(),
460460
&mut buf,
461461
&mut small_files,
462462
&NoErrors

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ impl<E: FileSourceInternalEvents> Glob<E> {
3535
.collect::<Option<_>>()?;
3636

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

4341
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
@@ -87,11 +87,13 @@ impl LogEvent {
8787
)
8888
}
8989

90+
#[must_use]
9091
pub fn with_batch_notifier(mut self, batch: &Arc<BatchNotifier>) -> Self {
9192
self.metadata = self.metadata.with_batch_notifier(batch);
9293
self
9394
}
9495

96+
#[must_use]
9597
pub fn with_batch_notifier_option(mut self, batch: &Option<Arc<BatchNotifier>>) -> Self {
9698
self.metadata = self.metadata.with_batch_notifier_option(batch);
9799
self

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

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

5959
impl EventMetadata {
6060
/// Replace the finalizers array with the given one.
61+
#[must_use]
6162
pub fn with_finalizer(mut self, finalizer: EventFinalizer) -> Self {
6263
self.finalizers = EventFinalizers::new(finalizer);
6364
self
6465
}
6566

6667
/// Replace the finalizer with a new one created from the given batch notifier.
68+
#[must_use]
6769
pub fn with_batch_notifier(self, batch: &Arc<BatchNotifier>) -> Self {
6870
self.with_finalizer(EventFinalizer::new(Arc::clone(batch)))
6971
}
7072

7173
/// Replace the finalizer with a new one created from the given optional batch notifier.
74+
#[must_use]
7275
pub fn with_batch_notifier_option(self, batch: &Option<Arc<BatchNotifier>>) -> Self {
7376
match batch {
7477
Some(batch) => self.with_finalizer(EventFinalizer::new(Arc::clone(batch))),
@@ -77,6 +80,7 @@ impl EventMetadata {
7780
}
7881

7982
/// Replace the schema definition with the given one.
83+
#[must_use]
8084
pub fn with_schema_definition(mut self, schema_definition: &Arc<schema::Definition>) -> Self {
8185
self.schema_definition = Arc::clone(schema_definition);
8286
self

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,18 +560,21 @@ impl Metric {
560560
}
561561

562562
#[inline]
563+
#[must_use]
563564
pub fn with_name(mut self, name: impl Into<String>) -> Self {
564565
self.series.name.name = name.into();
565566
self
566567
}
567568

568569
#[inline]
570+
#[must_use]
569571
pub fn with_namespace<T: Into<String>>(mut self, namespace: Option<T>) -> Self {
570572
self.series.name.namespace = namespace.map(Into::into);
571573
self
572574
}
573575

574576
#[inline]
577+
#[must_use]
575578
pub fn with_timestamp(mut self, timestamp: Option<DateTime<Utc>>) -> Self {
576579
self.data.timestamp = timestamp;
577580
self
@@ -581,23 +584,27 @@ impl Metric {
581584
self.metadata.add_finalizer(finalizer);
582585
}
583586

587+
#[must_use]
584588
pub fn with_batch_notifier(mut self, batch: &Arc<BatchNotifier>) -> Self {
585589
self.metadata = self.metadata.with_batch_notifier(batch);
586590
self
587591
}
588592

593+
#[must_use]
589594
pub fn with_batch_notifier_option(mut self, batch: &Option<Arc<BatchNotifier>>) -> Self {
590595
self.metadata = self.metadata.with_batch_notifier_option(batch);
591596
self
592597
}
593598

594599
#[inline]
600+
#[must_use]
595601
pub fn with_tags(mut self, tags: Option<MetricTags>) -> Self {
596602
self.series.tags = tags;
597603
self
598604
}
599605

600606
#[inline]
607+
#[must_use]
601608
pub fn with_value(mut self, value: MetricValue) -> Self {
602609
self.data.value = value;
603610
self
@@ -618,6 +625,7 @@ impl Metric {
618625
}
619626

620627
/// Rewrite this into a Metric with the data marked as absolute.
628+
#[must_use]
621629
pub fn into_absolute(self) -> Self {
622630
Self {
623631
series: self.series,
@@ -627,6 +635,7 @@ impl Metric {
627635
}
628636

629637
/// Rewrite this into a Metric with the data marked as incremental.
638+
#[must_use]
630639
pub fn into_incremental(self) -> Self {
631640
Self {
632641
series: self.series,
@@ -811,6 +820,7 @@ impl MetricSeries {
811820

812821
impl MetricData {
813822
/// Rewrite this data to mark it as absolute.
823+
#[must_use]
814824
pub fn into_absolute(self) -> Self {
815825
Self {
816826
timestamp: self.timestamp,
@@ -820,6 +830,7 @@ impl MetricData {
820830
}
821831

822832
/// Rewrite this data to mark it as incremental.
833+
#[must_use]
823834
pub fn into_incremental(self) -> Self {
824835
Self {
825836
timestamp: self.timestamp,

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

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

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

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,7 @@ impl From<sketch::AgentDdSketch> for MetricSketch {
382382
.into_iter()
383383
.map(|k| (k, k > 0))
384384
.map(|(k, pos)| {
385-
k.try_into()
386-
.unwrap_or_else(|_| if pos { i16::MAX } else { i16::MIN })
385+
k.try_into().unwrap_or(if pos { i16::MAX } else { i16::MIN })
387386
})
388387
.collect::<Vec<_>>();
389388
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
}

lib/vector-core/src/schema/definition.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl Definition {
5656
/// - Provided path is a root path (e.g. `.`).
5757
/// - Provided path points to a root-level array (e.g. `.[0]`).
5858
/// - Provided path has one or more coalesced segments (e.g. `.(foo | bar)`).
59+
#[must_use]
5960
pub fn required_field(
6061
mut self,
6162
path: impl Into<LookupBuf>,
@@ -102,6 +103,7 @@ impl Definition {
102103
/// # Panics
103104
///
104105
/// See `Definition::require_field`.
106+
#[must_use]
105107
pub fn optional_field(
106108
mut self,
107109
path: impl Into<LookupBuf>,
@@ -115,6 +117,7 @@ impl Definition {
115117
}
116118

117119
/// Set the kind for all unknown fields.
120+
#[must_use]
118121
pub fn unknown_fields(mut self, unknown: impl Into<Option<Kind>>) -> Self {
119122
self.collection.set_unknown(unknown);
120123
self
@@ -134,6 +137,7 @@ impl Definition {
134137
/// example, `.foo` might be set as optional, but `.foo.bar` as required. In this case, it
135138
/// means that the object at `.foo` is allowed to be missing, but if it's present, then it's
136139
/// required to have a `bar` field.
140+
#[must_use]
137141
pub fn merge(mut self, other: Self) -> Self {
138142
let mut optional = BTreeSet::default();
139143

0 commit comments

Comments
 (0)