Skip to content
Open
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
13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ lto = "fat"
[profile.bench]
debug = true

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] }
[lints]
workspace = true

[package.metadata.deb]
name = "vector"
Expand Down Expand Up @@ -136,6 +136,15 @@ members = [
"vdev",
]

[workspace.lints.rust]
# 'cfg(tokio_unstable)' used in vector; 'cfg(ddsketch_extended)' used in vector-core
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)', 'cfg(ddsketch_extended)'] }

[workspace.lints.clippy]
string_slice = "warn"
await_holding_lock = "warn"
let_underscore_must_use = "warn"

[workspace.dependencies]
antithesis-instrumentation = { version = "0.1", default-features = false, features = [] }
antithesis_sdk = { version = "0.2", default-features = false, features = [] }
Expand Down
3 changes: 3 additions & 0 deletions lib/codecs/Cargo.toml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For libs that are using custom lints like this one I think it's best that we use

[lints]
workspace = true

and add #![deny(clippy::unwrap_used)] in lib.rs so that workspace lints never fall out of date

Affected tomls:

  • lib/codecs/Cargo.toml
  • lib/dnsmsg-parser/Cargo.toml
  • lib/tracing-limit/Cargo.toml
  • lib/vector-core/Cargo.toml

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ publish = false

[lints.clippy]
unwrap-used = "deny"
string_slice = "warn"
await_holding_lock = "warn"
let_underscore_must_use = "warn"

[[bin]]
name = "generate-avro-fixtures"
Expand Down
3 changes: 3 additions & 0 deletions lib/codecs/src/encoding/format/parquet.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Derivative's Debug impl generates 'let _ = field.fmt(f)' which triggers this lint.
#![allow(clippy::let_underscore_must_use)]

//! Parquet batch format codec for batched event encoding
//!
//! Provides Apache Parquet format encoding with schema file support and auto-inference.
Expand Down
15 changes: 8 additions & 7 deletions lib/codecs/src/encoding/format/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ where
None => Cow::Borrowed(s), // All valid, zero allocation
Some((first_invalid_idx, _)) => {
let mut result = String::with_capacity(s.len());
result.push_str(&s[..first_invalid_idx]); // Copy valid prefix
for c in s[first_invalid_idx..].chars() {
let (valid_prefix, remainder) = s.split_at(first_invalid_idx);
result.push_str(valid_prefix);
for c in remainder.chars() {
result.push(if is_valid(c) { c } else { '_' });
}

Expand Down Expand Up @@ -320,7 +321,7 @@ impl SyslogMessage {
fn encode(&self, rfc: &SyslogRFC) -> String {
let mut result = String::with_capacity(256);

let _ = write!(result, "{}", self.pri.encode());
write!(result, "{}", self.pri.encode()).ok();

if *rfc == SyslogRFC::Rfc5424 {
result.push_str(SYSLOG_V1);
Expand All @@ -329,7 +330,7 @@ impl SyslogMessage {

match rfc {
SyslogRFC::Rfc3164 => {
let _ = write!(result, "{} ", self.timestamp.format("%b %e %H:%M:%S"));
write!(result, "{} ", self.timestamp.format("%b %e %H:%M:%S")).ok();
}
SyslogRFC::Rfc5424 => {
result.push_str(
Expand Down Expand Up @@ -435,12 +436,12 @@ impl StructuredData {
self.elements
.iter()
.fold(String::new(), |mut acc, (sd_id, sd_params)| {
let _ = write!(acc, "[{sd_id}");
write!(acc, "[{sd_id}").ok();
for (key, value) in sd_params {
let esc_val = escape_sd_value(value);
let _ = write!(acc, " {key}=\"{esc_val}\"");
write!(acc, " {key}=\"{esc_val}\"").ok();
}
let _ = write!(acc, "]");
write!(acc, "]").ok();
Comment on lines +439 to +444

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use push_str + format here to avoid .ok()s

Suggested change
write!(acc, "[{sd_id}").ok();
for (key, value) in sd_params {
let esc_val = escape_sd_value(value);
let _ = write!(acc, " {key}=\"{esc_val}\"");
write!(acc, " {key}=\"{esc_val}\"").ok();
}
let _ = write!(acc, "]");
write!(acc, "]").ok();
acc.push_str("[{sd_id}");
for (key, value) in sd_params {
let esc_val = escape_sd_value(value);
acc.push_str(&format!(" {key}=\"{esc_val}\""));
}
acc.push_str("]");

acc
})
}
Expand Down
3 changes: 3 additions & 0 deletions lib/dnsmsg-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ license = "MIT"

[lints.clippy]
unwrap-used = "forbid"
string_slice = "warn"
await_holding_lock = "warn"
let_underscore_must_use = "warn"

[dependencies]
data-encoding = "2.10"
Expand Down
3 changes: 3 additions & 0 deletions lib/docs-renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ authors = ["Vector Contributors <vector@datadoghq.com>"]
edition = "2024"
publish = false

[lints]
workspace = true

[dependencies]
anyhow.workspace = true
serde.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions lib/fakedata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2024"
publish = false
license = "MPL-2.0"

[lints]
workspace = true

[dependencies]
chrono.workspace = true
rand.workspace = true
3 changes: 3 additions & 0 deletions lib/file-source-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2024"
publish = false
license = "MIT"

[lints]
workspace = true

[target.'cfg(windows)'.dependencies]
libc.workspace = true
winapi = { version = "0.3", features = ["winioctl"] }
Expand Down
3 changes: 3 additions & 0 deletions lib/file-source/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2024"
publish = false
license = "MIT"

[lints]
workspace = true

[target.'cfg(windows)'.dependencies]
libc.workspace = true
winapi = { version = "0.3", features = ["winioctl"] }
Expand Down
3 changes: 3 additions & 0 deletions lib/k8s-e2e-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ description = "End-to-end tests of Vector in the Kubernetes environment"
publish = false
license = "MPL-2.0"

[lints]
workspace = true

[dependencies]
futures.workspace = true
k8s-openapi = { version = "0.27.0", default-features = false, features = ["v1_31"] }
Expand Down
3 changes: 3 additions & 0 deletions lib/k8s-test-framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ description = "Kubernetes Test Framework used to test Vector in Kubernetes"
publish = false
license = "MPL-2.0"

[lints]
workspace = true

[dependencies]
k8s-openapi = { version = "0.27.0", default-features = false, features = ["v1_31"] }
serde_json.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions lib/loki-logproto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints]
workspace = true

[dependencies]
prost.workspace = true
prost-types.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions lib/opentelemetry-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ authors = ["Vector Contributors <vector@datadoghq.com>"]
edition = "2024"
publish = false

[lints]
workspace = true

[build-dependencies]
prost-build.workspace = true
tonic-build.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions lib/prometheus-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ license = "MPL-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints]
workspace = true

[dependencies]
indexmap.workspace = true
nom.workspace = true
Expand Down
26 changes: 19 additions & 7 deletions lib/prometheus-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ impl GroupKind {
prefix_len: usize,
metric: Metric,
) -> Result<Option<Metric>, ParserError> {
#[expect(
clippy::string_slice,
reason = "prefix_len is always self.name.len(), a valid UTF-8 boundary"
)]
let suffix = &metric.name[prefix_len..];
let mut key = GroupKey {
timestamp: metric.timestamp,
Expand Down Expand Up @@ -328,15 +332,23 @@ struct MetricGroupSet(IndexMap<String, GroupKind>);

impl MetricGroupSet {
fn get_group<'a>(&'a mut self, name: &str) -> (usize, &'a String, &'a mut GroupKind) {
let len = name.len();
let name = if self.0.contains_key(name) {
name
} else if name.ends_with("_bucket") && self.0.contains_key(&name[..len - 7]) {
&name[..len - 7]
} else if name.ends_with("_sum") && self.0.contains_key(&name[..len - 4]) {
&name[..len - 4]
} else if name.ends_with("_count") && self.0.contains_key(&name[..len - 6]) {
&name[..len - 6]
} else if let Some(base) = name
.strip_suffix("_bucket")
.filter(|b| self.0.contains_key(*b))
{
base
} else if let Some(base) = name
.strip_suffix("_sum")
.filter(|b| self.0.contains_key(*b))
{
base
} else if let Some(base) = name
.strip_suffix("_count")
.filter(|b| self.0.contains_key(*b))
{
base
} else {
self.0
.insert(name.into(), GroupKind::new(MetricKind::Untyped));
Expand Down
3 changes: 3 additions & 0 deletions lib/tracing-limit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ license = "MPL-2.0"

[lints.clippy]
unwrap-used = "forbid"
string_slice = "warn"
await_holding_lock = "warn"
let_underscore_must_use = "warn"

[dependencies]
tracing-core = { version = "0.1", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions lib/vector-api-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2024"
publish = false
license = "MPL-2.0"

[lints]
workspace = true

[dependencies]
# gRPC
tonic.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions lib/vector-buffers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["Vector Contributors <vector@datadoghq.com>"]
edition = "2024"
publish = false

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] }
[lints]
workspace = true

[dependencies]
async-recursion = "1.1.1"
Expand Down
3 changes: 3 additions & 0 deletions lib/vector-buffers/src/topology/channel/sender.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Derivative's Debug impl generates 'let _ = field.fmt(f)' which triggers this lint.
#![allow(clippy::let_underscore_must_use)]

use std::{sync::Arc, time::Instant};

use async_recursion::async_recursion;
Expand Down
3 changes: 3 additions & 0 deletions lib/vector-common-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2024"
license = "MPL-2.0"

[lints]
workspace = true

[lib]
proc-macro = true

Expand Down
3 changes: 3 additions & 0 deletions lib/vector-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2024"
publish = false
license = "MPL-2.0"

[lints]
workspace = true

[features]
default = [
"btreemap",
Expand Down
4 changes: 2 additions & 2 deletions lib/vector-common/src/event_test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ pub fn record_internal_event(event: &str) {
// Remove leading '&'
let event = event.strip_prefix('&').unwrap_or(event);
// Remove trailing '{fields…}'
let event = event.find('{').map_or(event, |par| &event[..par]);
let event = event.split_once('{').map_or(event, |(before, _)| before);
// Remove trailing '::from…'
let event = event.find(':').map_or(event, |colon| &event[..colon]);
let event = event.split_once(':').map_or(event, |(before, _)| before);

EVENTS_RECORDED.with(|er| er.borrow_mut().insert(event.trim().into()));
}
Expand Down
3 changes: 3 additions & 0 deletions lib/vector-config-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2024"
license = "MPL-2.0"

[lints]
workspace = true

[dependencies]
convert_case.workspace = true
darling.workspace = true
Expand Down
9 changes: 3 additions & 6 deletions lib/vector-config-common/src/schema/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,9 @@ impl SchemaGenerator {
..
}) => {
let definitions_path = &self.settings().definitions_path;
if schema_ref.starts_with(definitions_path) {
let name = &schema_ref[definitions_path.len()..];
self.definitions.get(name)
} else {
None
}
schema_ref
.strip_prefix(definitions_path.as_str())
.and_then(|name| self.definitions.get(name))
}
_ => None,
}
Expand Down
3 changes: 3 additions & 0 deletions lib/vector-config-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2024"
license = "MPL-2.0"

[lints]
workspace = true

[lib]
proc-macro = true

Expand Down
3 changes: 3 additions & 0 deletions lib/vector-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition = "2024"
publish = false
license = "MPL-2.0"

[lints]
workspace = true

[[test]]
name = "integration"
path = "tests/integration/lib.rs"
Expand Down
4 changes: 3 additions & 1 deletion lib/vector-config/tests/integration/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ impl TryFrom<String> for SocketListenAddr {
Err(_) => {
let fd: usize = match input.as_str() {
"systemd" => Ok(0),
s if s.starts_with("systemd#") => s[8..]
s if s.starts_with("systemd#") => s
.strip_prefix("systemd#")
.unwrap()
.parse::<usize>()
.map_err(|_| "failed to parse usize".to_string())?
.checked_sub(1)
Expand Down
4 changes: 2 additions & 2 deletions lib/vector-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["Vector Contributors <vector@datadoghq.com>"]
edition = "2024"
publish = false

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ddsketch_extended)'] }
[lints]
workspace = true

[dependencies]
async-trait.workspace = true
Expand Down
6 changes: 5 additions & 1 deletion lib/vector-core/src/event/util/log/all_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ mod test {
.map(|(k, v)| (k.into(), v))
.collect();
// Compare without the leading `"` char so that the order is the same as the collected fields.
expected.sort_by(|(a, _), (b, _)| a[1..].cmp(&b[1..]));
expected.sort_by(|(a, _), (b, _)| {
a.strip_prefix('"')
.unwrap_or(a)
.cmp(b.strip_prefix('"').unwrap_or(b))
});

assert_eq!(collected, expected);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-core/src/event/vrl_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl Target for VrlTarget {
metric.remove_tags();
for (field, value) in &value {
set_metric_tag_values(
field[..].into(),
field.as_str().into(),
value,
metric,
*multi_value_tags,
Expand Down
Loading
Loading