Skip to content

chore: Apply clippy lints from 1.59.0 #11595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/datadog/grok/src/matchers/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,12 @@ fn parse_tz_id_or_name(tz: &str) -> Result<FixedOffset, String> {
}

fn parse_offset(tz: &str) -> Result<FixedOffset, String> {
let offset_format;
if tz.len() <= 3 {
// +5, -12
let hours_diff = tz.parse::<i32>().map_err(|e| e.to_string())?;
return Ok(FixedOffset::east(hours_diff * 3600));
}
if tz.contains(':') {
offset_format = "%:z";
} else {
offset_format = "%z";
}
let offset_format = if tz.contains(':') { "%:z" } else { "%z" };
// apparently the easiest way to parse tz offset is parsing the complete datetime
let date_str = format!("2020-04-12 22:10:57 {}", tz);
let datetime =
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/search-syntax/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn normalize_fields<T: AsRef<str>>(value: T) -> Vec<Field> {
.collect();
}

let field = match value.replace("@", "custom.") {
let field = match value.replace('@', "custom.") {
v if value.starts_with('@') => Field::Facet(v),
v if DEFAULT_FIELDS.contains(&v.as_ref()) => Field::Default(v),
v if RESERVED_ATTRIBUTES.contains(&v.as_ref()) => Field::Reserved(v),
Expand Down
4 changes: 2 additions & 2 deletions lib/dnsmsg-parser/src/dns_message_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ fn parse_character_string(decoder: &mut BinDecoder<'_>) -> DnsParserResult<Strin
"Unexpected data length: expected {}, got {}. Raw data {}",
len,
raw_data.len(),
format_bytes_as_hex_string(&raw_data.to_vec())
format_bytes_as_hex_string(raw_data)
),
}),
}
Expand Down Expand Up @@ -1106,7 +1106,7 @@ fn parse_domain_name(decoder: &mut BinDecoder<'_>) -> DnsParserResult<Name> {
}

fn escape_string_for_text_representation(original_string: String) -> String {
original_string.replace("\\", "\\\\").replace("\"", "\\\"")
original_string.replace('\\', "\\\\").replace('\"', "\\\"")
}

fn parse_unknown_record_type(rtype: u16) -> Option<String> {
Expand Down
7 changes: 1 addition & 6 deletions lib/file-source/src/fingerprinter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,7 @@ mod test {
let mut buf = Vec::new();
let mut small_files = HashSet::new();
assert!(fingerprinter
.get_fingerprint_or_log_error(
&target_dir.path().to_owned(),
&mut buf,
&mut small_files,
&NoErrors
)
.get_fingerprint_or_log_error(target_dir.path(), &mut buf, &mut small_files, &NoErrors)
.is_none());
}

Expand Down
3 changes: 1 addition & 2 deletions lib/file-source/src/paths_provider/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ impl<E: FileSourceInternalEvents> Glob<E> {

let exclude_patterns = exclude_patterns
.iter()
.map(|path| path.to_str().map(|path| Pattern::new(path).ok()))
.flatten()
.filter_map(|path| path.to_str().map(|path| Pattern::new(path).ok()))
.collect::<Option<Vec<_>>>()?;

Some(Self {
Expand Down
2 changes: 1 addition & 1 deletion lib/k8s-e2e-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn get_override_name(namespace: &str, suffix: &str) -> String {

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

/// Create config adding fullnameOverride entry. This allows multiple tests
Expand Down
8 changes: 4 additions & 4 deletions lib/k8s-test-framework/src/kubernetes_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ pub async fn get(kubectl_command: &str) -> Result<K8sVersion> {
let json: serde_json::Value = serde_json::from_slice(&reader.stdout)?;

Ok(K8sVersion {
major: json["serverVersion"]["major"].to_string().replace("\"", ""),
minor: json["serverVersion"]["minor"].to_string().replace("\"", ""),
major: json["serverVersion"]["major"].to_string().replace('\"', ""),
minor: json["serverVersion"]["minor"].to_string().replace('\"', ""),
platform: json["serverVersion"]["platform"]
.to_string()
.replace("\"", ""),
.replace('\"', ""),
git_version: json["serverVersion"]["gitVersion"]
.to_string()
.replace("\"", ""),
.replace('\"', ""),
})
}

Expand Down
4 changes: 2 additions & 2 deletions lib/lookup/src/lookup_buf/segmentbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Arbitrary for FieldBuf {
let name = (0..len)
.map(|_| chars[usize::arbitrary(g) % chars.len()])
.collect::<String>()
.replace(r#"""#, r#"\""#);
.replace('"', r#"\""#);
FieldBuf::from(name)
}

Expand All @@ -74,7 +74,7 @@ impl Arbitrary for FieldBuf {
.shrink()
.filter(|name| !name.is_empty())
.map(|name| {
let name = name.replace(r#"""#, r#"/""#);
let name = name.replace('"', r#"/""#);
FieldBuf::from(name)
}),
)
Expand Down
2 changes: 2 additions & 0 deletions lib/value/src/value/api.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::use_self)] // I don't think Self can be used here, it creates a cycle

use async_graphql::scalar;

use crate::value::Value;
Expand Down
6 changes: 3 additions & 3 deletions lib/value/src/value/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ impl fmt::Display for Value {
f,
r#""{}""#,
String::from_utf8_lossy(val)
.replace(r#"\"#, r#"\\"#)
.replace(r#"""#, r#"\""#)
.replace("\n", r#"\n"#)
.replace('\\', r#"\\"#)
.replace('"', r#"\""#)
.replace('\n', r#"\n"#)
),
Value::Integer(val) => write!(f, "{}", val),
Value::Float(val) => write!(f, "{}", val),
Expand Down
1 change: 1 addition & 0 deletions lib/value/src/value/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ impl Value {
///
/// For example, given the path `.foo.bar` and value `true`, the return
/// value would be an object representing `{ "foo": { "bar": true } }`.
#[must_use]
pub fn at_path(mut self, path: &LookupBuf) -> Self {
for segment in path.as_segments().iter().rev() {
match segment {
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-buffers/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl BufferConfig {
{
let mut builder = TopologyBuilder::default();

for stage in self.stages.iter().copied() {
for stage in &self.stages {
stage.add_to_builder(&mut builder, data_dir.clone(), buffer_id.clone())?;
}

Expand Down
1 change: 1 addition & 0 deletions lib/vector-core/src/config/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl ComponentKey {
&self.id
}

#[must_use]
pub fn join<D: fmt::Display>(&self, name: D) -> Self {
Self {
id: format!("{}.{}", self.id, name),
Expand Down
2 changes: 2 additions & 0 deletions lib/vector-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl Output {
}

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

impl AcknowledgementsConfig {
#[must_use]
pub fn merge_default(&self, other: &Self) -> Self {
let enabled = self.enabled.or(other.enabled);
Self { enabled }
Expand Down
7 changes: 4 additions & 3 deletions lib/vector-core/src/config/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl ProxyConfig {
// overrides current proxy configuration with other configuration
// if `self` is the global config and `other` the component config,
// if both have the `http` proxy set, the one from `other` should be kept
#[must_use]
pub fn merge(&self, other: &Self) -> Self {
let no_proxy = if other.no_proxy.is_empty() {
self.no_proxy.clone()
Expand Down Expand Up @@ -188,7 +189,7 @@ mod tests {
let result = first.merge(&second).merge(&third);
assert_eq!(result.http, Some("http://1.2.3.4:5678".into()));
assert_eq!(result.https, Some("https://2.3.4.5:9876".into()));
assert!(result.no_proxy.matches(&"localhost".to_string()));
assert!(result.no_proxy.matches("localhost"));
}

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

#[test]
Expand Down
1 change: 1 addition & 0 deletions lib/vector-core/src/event/finalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ impl EventStatus {
/// Passing a new status of `Dropped` is a programming error and
/// will panic in debug/test builds.
#[allow(clippy::match_same_arms)] // False positive: https://github.com/rust-lang/rust-clippy/issues/860
#[must_use]
pub fn update(self, status: Self) -> Self {
match (self, status) {
// `Recorded` always overwrites existing status and is never updated
Expand Down
2 changes: 2 additions & 0 deletions lib/vector-core/src/event/log_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ impl LogEvent {
)
}

#[must_use]
pub fn with_batch_notifier(mut self, batch: &Arc<BatchNotifier>) -> Self {
self.metadata = self.metadata.with_batch_notifier(batch);
self
}

#[must_use]
pub fn with_batch_notifier_option(mut self, batch: &Option<Arc<BatchNotifier>>) -> Self {
self.metadata = self.metadata.with_batch_notifier_option(batch);
self
Expand Down
4 changes: 4 additions & 0 deletions lib/vector-core/src/event/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ impl ByteSizeOf for EventMetadata {

impl EventMetadata {
/// Replace the finalizers array with the given one.
#[must_use]
pub fn with_finalizer(mut self, finalizer: EventFinalizer) -> Self {
self.finalizers = EventFinalizers::new(finalizer);
self
}

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

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

/// Replace the schema definition with the given one.
#[must_use]
pub fn with_schema_definition(mut self, schema_definition: &Arc<schema::Definition>) -> Self {
self.schema_definition = Arc::clone(schema_definition);
self
Expand Down
11 changes: 11 additions & 0 deletions lib/vector-core/src/event/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,18 +560,21 @@ impl Metric {
}

#[inline]
#[must_use]
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.series.name.name = name.into();
self
}

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

#[inline]
#[must_use]
pub fn with_timestamp(mut self, timestamp: Option<DateTime<Utc>>) -> Self {
self.data.timestamp = timestamp;
self
Expand All @@ -581,23 +584,27 @@ impl Metric {
self.metadata.add_finalizer(finalizer);
}

#[must_use]
pub fn with_batch_notifier(mut self, batch: &Arc<BatchNotifier>) -> Self {
self.metadata = self.metadata.with_batch_notifier(batch);
self
}

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

#[inline]
#[must_use]
pub fn with_tags(mut self, tags: Option<MetricTags>) -> Self {
self.series.tags = tags;
self
}

#[inline]
#[must_use]
pub fn with_value(mut self, value: MetricValue) -> Self {
self.data.value = value;
self
Expand All @@ -618,6 +625,7 @@ impl Metric {
}

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

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

impl MetricData {
/// Rewrite this data to mark it as absolute.
#[must_use]
pub fn into_absolute(self) -> Self {
Self {
timestamp: self.timestamp,
Expand All @@ -820,6 +830,7 @@ impl MetricData {
}

/// Rewrite this data to mark it as incremental.
#[must_use]
pub fn into_incremental(self) -> Self {
Self {
timestamp: self.timestamp,
Expand Down
2 changes: 2 additions & 0 deletions lib/vector-core/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ impl Event {
}
}

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

#[must_use]
pub fn with_batch_notifier_option(self, batch: &Option<Arc<BatchNotifier>>) -> Self {
match self {
Self::Log(log) => log.with_batch_notifier_option(batch).into(),
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-core/src/event/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl From<sketch::AgentDdSketch> for MetricSketch {
.map(|k| (k, k > 0))
.map(|(k, pos)| {
k.try_into()
.unwrap_or_else(|_| if pos { i16::MAX } else { i16::MIN })
.unwrap_or(if pos { i16::MAX } else { i16::MIN })
})
.collect::<Vec<_>>();
let counts = sketch
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-core/src/event/util/log/all_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> FieldsIter<'a> {
None => return res,
Some(PathComponent::Key(key)) => {
if key.contains('.') {
res.push_str(&key.replace(".", "\\."));
res.push_str(&key.replace('.', "\\."));
} else {
res.push_str(key);
}
Expand Down
Loading