From 78e0636bf934abce24b2964b8c40dbe7e3825298 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Fri, 13 Feb 2026 13:10:56 +0000 Subject: [PATCH 1/5] Move linting to Cargo.toml --- .github/workflows/rust.yml | 2 +- Cargo.toml | 28 ++++++++++++++++++++++++++++ clippy.toml | 1 + engine/Cargo.toml | 2 ++ engine/src/lib.rs | 3 --- ffi/Cargo.toml | 2 ++ ffi/src/lib.rs | 3 --- 7 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 clippy.toml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 94cf9aa7..7aaf4caa 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -27,7 +27,7 @@ jobs: - name: Run tests run: cargo test --verbose - name: Run clippy - run: cargo clippy --verbose --all-targets -- -D clippy::all + run: cargo clippy --all-targets -- -Dwarnings fmt: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 655019b7..c95ed1f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,34 @@ wasm-bindgen = { version = "0.2.108", features = ["serde-serialize"] } wildcard = "0.3.0" wirefilter = { package = "wirefilter-engine", path = "engine" } +# tombi: format.rules.table-keys-order.disabled = true +[workspace.lints.clippy] +# groups +all = { level = "warn", priority = -1 } +cargo = { level = "warn", priority = -1 } +# group exceptions +cargo_common_metadata = "allow" +multiple_crate_versions = "allow" + +# tombi: format.rules.table-keys-order.disabled = true +[workspace.lints.rust] +# groups +deprecated-safe = { level = "warn", priority = -1 } +future-incompatible = { level = "warn", priority = -1 } +keyword-idents = { level = "warn", priority = -1 } +let-underscore = { level = "warn", priority = -1 } +nonstandard-style = { level = "warn", priority = -1 } +refining-impl-trait = { level = "warn", priority = -1 } +rust-2018-compatibility = { level = "warn", priority = -1 } +rust-2018-idioms = { level = "warn", priority = -1 } +rust-2021-compatibility = { level = "warn", priority = -1 } +rust-2024-compatibility = { level = "warn", priority = -1 } +unknown-or-malformed-diagnostic-attributes = { level = "warn", priority = -1 } +unused = { level = "warn", priority = -1 } +warnings = { level = "warn", priority = -1 } +# group exceptions +let-underscore-drop = "allow" + [profile.dev] panic = "unwind" diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 00000000..592cea90 --- /dev/null +++ b/clippy.toml @@ -0,0 +1 @@ +lint-commented-code = true diff --git a/engine/Cargo.toml b/engine/Cargo.toml index bf7b9b00..2bf126d2 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -1,3 +1,5 @@ +lints.workspace = true + [package] name = "wirefilter-engine" version.workspace = true diff --git a/engine/src/lib.rs b/engine/src/lib.rs index e9953d1d..57724963 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -55,9 +55,6 @@ //! } //! ``` #![warn(missing_docs)] -#![warn(rust_2018_idioms)] -#![allow(clippy::upper_case_acronyms)] -#![allow(clippy::needless_raw_string_hashes)] #[macro_use] mod lex; diff --git a/ffi/Cargo.toml b/ffi/Cargo.toml index fd588f1c..37f57859 100644 --- a/ffi/Cargo.toml +++ b/ffi/Cargo.toml @@ -1,3 +1,5 @@ +lints.workspace = true + [package] name = "wirefilter-ffi" version.workspace = true diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 7fe3ecbb..31ce8eb0 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -1,6 +1,3 @@ -#![allow(clippy::not_unsafe_ptr_arg_deref)] -#![warn(rust_2018_idioms)] - mod cstring; pub mod panic; From 5fdb61ed6d89dfe588a31a0e71eba39f5387e6f1 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Fri, 13 Feb 2026 13:13:31 +0000 Subject: [PATCH 2/5] Fix lints --- engine/benches/bench.rs | 6 +++--- engine/src/ast/field_expr.rs | 3 +-- engine/src/ast/function_expr.rs | 13 +------------ engine/src/ast/index_expr.rs | 2 +- engine/src/ast/logical_expr.rs | 3 +-- engine/src/rhs_types/bytes.rs | 1 - engine/src/scheme.rs | 1 - ffi/src/lib.rs | 5 ++++- wasm/src/lib.rs | 1 - 9 files changed, 11 insertions(+), 24 deletions(-) diff --git a/engine/benches/bench.rs b/engine/benches/bench.rs index 33a351ec..f68b211d 100644 --- a/engine/benches/bench.rs +++ b/engine/benches/bench.rs @@ -87,7 +87,7 @@ impl>> FieldBench<'_, T> { builder.add_function(name, function.clone()).unwrap(); } let scheme = builder.build(); - move |b: &mut Bencher| { + move |b: &mut Bencher<'_>| { b.iter(|| scheme.parse(filter).unwrap()); } }); @@ -103,7 +103,7 @@ impl>> FieldBench<'_, T> { builder.add_function(name, function.clone()).unwrap(); } let scheme = builder.build(); - move |b: &mut Bencher| { + move |b: &mut Bencher<'_>| { let filter = scheme.parse(filter).unwrap(); b.iter_with_setup(move || filter.clone(), FilterAst::compile); @@ -121,7 +121,7 @@ impl>> FieldBench<'_, T> { builder.add_function(name, function.clone()).unwrap(); } let scheme = builder.build(); - move |b: &mut Bencher, values: &[T]| { + move |b: &mut Bencher<'_>, values: &[T]| { let filter = scheme.parse(filter).unwrap(); let filter = filter.compile(); diff --git a/engine/src/ast/field_expr.rs b/engine/src/ast/field_expr.rs index 2a171a1e..71513919 100644 --- a/engine/src/ast/field_expr.rs +++ b/engine/src/ast/field_expr.rs @@ -791,7 +791,7 @@ impl Expr for ComparisonExpr { } #[cfg(test)] -#[allow(clippy::bool_assert_comparison)] +#[expect(clippy::bool_assert_comparison)] mod tests { use super::*; use crate::ast::function_expr::{FunctionCallArgExpr, FunctionCallExpr}; @@ -843,7 +843,6 @@ mod tests { } } - #[allow(clippy::unnecessary_wraps)] fn concat_function<'a>(args: FunctionArgs<'_, 'a>) -> Option> { let mut output = Vec::new(); for (index, arg) in args.enumerate() { diff --git a/engine/src/ast/function_expr.rs b/engine/src/ast/function_expr.rs index c9808941..cc8c3ba0 100644 --- a/engine/src/ast/function_expr.rs +++ b/engine/src/ast/function_expr.rs @@ -2,7 +2,7 @@ use super::ValueExpr; use super::parse::FilterParser; use super::visitor::{Visitor, VisitorMut}; use crate::FunctionRef; -use crate::ast::field_expr::{ComparisonExpr, ComparisonOp, ComparisonOpExpr}; +use crate::ast::field_expr::{ComparisonExpr, ComparisonOp}; use crate::ast::index_expr::IndexExpr; use crate::ast::logical_expr::{LogicalExpr, UnaryOp}; use crate::compiler::Compiler; @@ -88,17 +88,6 @@ impl FunctionCallArgExpr { FunctionCallArgExpr::Logical(_) => 0, } } - - #[allow(dead_code)] - pub(crate) fn simplify(self) -> Self { - match self { - FunctionCallArgExpr::Logical(LogicalExpr::Comparison(ComparisonExpr { - lhs, - op: ComparisonOpExpr::IsTrue, - })) => FunctionCallArgExpr::IndexExpr(lhs), - _ => self, - } - } } impl<'i, 's> LexWith<'i, &FilterParser<'s>> for FunctionCallArgExpr { diff --git a/engine/src/ast/index_expr.rs b/engine/src/ast/index_expr.rs index f1f8443c..ea26571e 100644 --- a/engine/src/ast/index_expr.rs +++ b/engine/src/ast/index_expr.rs @@ -28,7 +28,7 @@ pub struct IndexExpr { pub indexes: Vec, } -#[allow(clippy::manual_ok_err)] +#[expect(clippy::manual_ok_err)] #[inline] pub fn ok_ref(result: &Result) -> Option<&T> { match result { diff --git a/engine/src/ast/logical_expr.rs b/engine/src/ast/logical_expr.rs index 4f1790a0..944a22c1 100644 --- a/engine/src/ast/logical_expr.rs +++ b/engine/src/ast/logical_expr.rs @@ -318,8 +318,7 @@ impl Expr for LogicalExpr { } #[test] -#[allow(clippy::bool_assert_comparison)] -#[allow(clippy::cognitive_complexity)] +#[expect(clippy::bool_assert_comparison)] fn test() { use super::field_expr::ComparisonExpr; use crate::ast::field_expr::{ComparisonOpExpr, IdentifierExpr}; diff --git a/engine/src/rhs_types/bytes.rs b/engine/src/rhs_types/bytes.rs index 45e51b59..7ecefb21 100644 --- a/engine/src/rhs_types/bytes.rs +++ b/engine/src/rhs_types/bytes.rs @@ -61,7 +61,6 @@ impl Serialize for BytesExpr { // We can get away with `Eq` invariant though because we do want // `Bytes == Bytes` to check enum tags but `Bytes == &[u8]` to ignore them, and // consistency of the latter is all that matters for `Borrow` consumers. -#[allow(clippy::derived_hash_with_manual_eq)] impl Hash for BytesExpr { #[inline] fn hash(&self, h: &mut H) { diff --git a/engine/src/scheme.rs b/engine/src/scheme.rs index db21743f..d98b1364 100644 --- a/engine/src/scheme.rs +++ b/engine/src/scheme.rs @@ -28,7 +28,6 @@ pub struct SchemeMismatchError; /// * A map key with [`FieldIndex::MapKey`] /// /// ``` -/// #[allow(dead_code)] /// enum FieldIndex { /// ArrayIndex(u32), /// MapKey(String), diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 31ce8eb0..321bac5a 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -511,6 +511,7 @@ pub extern "C" fn wirefilter_serialize_execution_context_to_json( serde_json::to_string(exec_context.as_ref()).into() } +#[expect(clippy::not_unsafe_ptr_arg_deref)] #[unsafe(no_mangle)] pub extern "C" fn wirefilter_deserialize_json_to_execution_context( exec_context: &mut ExecutionContext<'_>, @@ -534,6 +535,7 @@ pub extern "C" fn wirefilter_free_execution_context(exec_context: Box, @@ -578,6 +580,7 @@ pub extern "C" fn wirefilter_add_int_value_to_execution_context( exec_context.set_field_value_from_name(name, value).is_ok() } +#[expect(clippy::not_unsafe_ptr_arg_deref)] #[unsafe(no_mangle)] pub extern "C" fn wirefilter_add_bytes_value_to_execution_context( exec_context: &mut ExecutionContext<'_>, @@ -822,7 +825,7 @@ pub extern "C" fn wirefilter_get_version() -> StaticRustAllocatedString { } #[cfg(test)] -#[allow(clippy::bool_assert_comparison)] +#[expect(clippy::bool_assert_comparison)] mod ffi_test { use super::*; use regex_automata::meta::Regex; diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 283bbd83..bbbd87a2 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -3,7 +3,6 @@ use wasm_bindgen::prelude::*; #[wasm_bindgen] pub struct Scheme(wirefilter::Scheme); -#[allow(clippy::needless_pass_by_value)] fn into_js_error(err: impl std::error::Error) -> JsValue { js_sys::Error::new(&err.to_string()).into() } From 2fa54b1905585884be9fe156b00d449b2a8e57a3 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Fri, 13 Feb 2026 13:23:17 +0000 Subject: [PATCH 3/5] Add rust lints --- Cargo.toml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index c95ed1f1..3989cac2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,22 @@ unused = { level = "warn", priority = -1 } warnings = { level = "warn", priority = -1 } # group exceptions let-underscore-drop = "allow" +# ungrouped +closure-returning-async-block = "warn" +deprecated-in-future = "warn" +deref-into-dyn-supertrait = "warn" +impl-trait-redundant-captures = "warn" +linker-messages = "warn" +macro-use-extern-crate = "warn" +meta-variable-misuse = "warn" +redundant-imports = "warn" +redundant-lifetimes = "warn" +single-use-lifetimes = "warn" +trivial-numeric-casts = "warn" +unit-bindings = "warn" +unused-import-braces = "warn" +unused-lifetimes = "warn" +unused-qualifications = "warn" [profile.dev] panic = "unwind" From 57b4a43c2491fe59e60e03dd739f551ea845edce Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Thu, 26 Feb 2026 15:22:16 +0000 Subject: [PATCH 4/5] Auto fixes --- engine/benches/bench.rs | 1 - engine/src/ast/field_expr.rs | 4 ++-- engine/src/ast/function_expr.rs | 4 ++-- engine/src/filter.rs | 2 +- engine/src/functions/all.rs | 4 ++-- engine/src/functions/any.rs | 4 ++-- engine/src/functions/concat.rs | 4 ++-- engine/src/functions/mod.rs | 14 +++++++------- engine/src/lhs_types/array.rs | 2 +- engine/src/lhs_types/bytes.rs | 2 +- engine/src/lhs_types/map.rs | 2 +- engine/src/list_matcher.rs | 12 ++++++------ engine/src/rhs_types/bytes.rs | 4 ++-- engine/src/rhs_types/ip.rs | 2 +- engine/src/scheme.rs | 2 +- engine/src/types.rs | 28 ++++++++++++++-------------- ffi/src/cstring.rs | 6 +++--- ffi/src/lib.rs | 4 ++-- 18 files changed, 50 insertions(+), 51 deletions(-) diff --git a/engine/benches/bench.rs b/engine/benches/bench.rs index f68b211d..0b44f1af 100644 --- a/engine/benches/bench.rs +++ b/engine/benches/bench.rs @@ -6,7 +6,6 @@ use std::alloc::System; static A: System = System; use criterion::{Bencher, Criterion, criterion_group, criterion_main}; -use std::clone::Clone; use std::fmt::Debug; use std::net::IpAddr; use wirefilter::{ diff --git a/engine/src/ast/field_expr.rs b/engine/src/ast/field_expr.rs index 71513919..c60646a7 100644 --- a/engine/src/ast/field_expr.rs +++ b/engine/src/ast/field_expr.rs @@ -946,10 +946,10 @@ mod tests { pub struct NumMListDefinition {} impl ListDefinition for NumMListDefinition { - fn deserialize_matcher<'de>( + fn deserialize_matcher( &self, _: Type, - deserializer: &mut dyn erased_serde::Deserializer<'de>, + deserializer: &mut dyn erased_serde::Deserializer<'_>, ) -> Result, erased_serde::Error> { let matcher = erased_serde::deserialize::(deserializer)?; Ok(Box::new(matcher)) diff --git a/engine/src/ast/function_expr.rs b/engine/src/ast/function_expr.rs index cc8c3ba0..3a254807 100644 --- a/engine/src/ast/function_expr.rs +++ b/engine/src/ast/function_expr.rs @@ -261,10 +261,10 @@ impl ValueExpr for FunctionCallExpr { let first = args.remove(0); #[inline(always)] - fn compute<'s, 'a, I: ExactSizeIterator>>( + fn compute<'a, I: ExactSizeIterator>>( first: CompiledValueResult<'a>, call: &( - dyn for<'b> Fn(FunctionArgs<'_, 'b>) -> Option> + Sync + Send + 's + dyn for<'b> Fn(FunctionArgs<'_, 'b>) -> Option> + Sync + Send + '_ ), return_type: Type, f: impl Fn(LhsValue<'a>) -> I, diff --git a/engine/src/filter.rs b/engine/src/filter.rs index 510672cf..7d531847 100644 --- a/engine/src/filter.rs +++ b/engine/src/filter.rs @@ -184,7 +184,7 @@ pub struct Filter { scheme: Scheme, } -impl std::fmt::Debug for Filter { +impl fmt::Debug for Filter { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Filter") .field("root", &self.root_expr) diff --git a/engine/src/functions/all.rs b/engine/src/functions/all.rs index b78cb8e8..faf4fce5 100644 --- a/engine/src/functions/all.rs +++ b/engine/src/functions/all.rs @@ -58,8 +58,8 @@ impl FunctionDefinition for AllFunction { (1, Some(0)) } - fn compile<'s>( - &'s self, + fn compile( + &self, _: &mut dyn ExactSizeIterator>, _: Option, ) -> Box Fn(FunctionArgs<'i, 'a>) -> Option> + Sync + Send + 'static> diff --git a/engine/src/functions/any.rs b/engine/src/functions/any.rs index a9f90b76..be59b63f 100644 --- a/engine/src/functions/any.rs +++ b/engine/src/functions/any.rs @@ -58,8 +58,8 @@ impl FunctionDefinition for AnyFunction { (1, Some(0)) } - fn compile<'s>( - &'s self, + fn compile( + &self, _: &mut dyn ExactSizeIterator>, _: Option, ) -> Box Fn(FunctionArgs<'i, 'a>) -> Option> + Sync + Send + 'static> diff --git a/engine/src/functions/concat.rs b/engine/src/functions/concat.rs index 1d493d93..b885312b 100644 --- a/engine/src/functions/concat.rs +++ b/engine/src/functions/concat.rs @@ -90,8 +90,8 @@ impl FunctionDefinition for ConcatFunction { (2, None) } - fn compile<'s>( - &'s self, + fn compile( + &self, _: &mut dyn ExactSizeIterator>, _: Option, ) -> Box Fn(FunctionArgs<'i, 'a>) -> Option> + Sync + Send + 'static> diff --git a/engine/src/functions/mod.rs b/engine/src/functions/mod.rs index 5129791a..9b9db98b 100644 --- a/engine/src/functions/mod.rs +++ b/engine/src/functions/mod.rs @@ -286,7 +286,7 @@ impl<'a> FunctionParam<'a> { pub struct FunctionDefinitionContext { inner: Box, clone_cb: fn(&(dyn Any + Send + Sync)) -> Box, - fmt_cb: fn(&(dyn Any + Send + Sync), &mut std::fmt::Formatter<'_>) -> std::fmt::Result, + fmt_cb: fn(&(dyn Any + Send + Sync), &mut fmt::Formatter<'_>) -> fmt::Result, } impl FunctionDefinitionContext { @@ -298,8 +298,8 @@ impl FunctionDefinitionContext { fn fmt_any( t: &(dyn Any + Send + Sync), - f: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { + f: &mut fmt::Formatter<'_>, + ) -> fmt::Result { t.downcast_ref::().unwrap().fmt(f) } @@ -364,8 +364,8 @@ impl Clone for FunctionDefinitionContext { } } -impl std::fmt::Debug for FunctionDefinitionContext { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl Debug for FunctionDefinitionContext { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "FunctionDefinitionContext(")?; (self.fmt_cb)(&*self.inner, f)?; write!(f, ")")?; @@ -409,7 +409,7 @@ pub trait FunctionDefinition: Debug + Send + Sync { // Simple function APIs -type FunctionPtr = for<'i, 'a> fn(FunctionArgs<'i, 'a>) -> Option>; +type FunctionPtr = for<'a> fn(FunctionArgs<'_, 'a>) -> Option>; /// Wrapper around a function pointer providing the runtime implementation. #[derive(Clone, Copy)] @@ -422,7 +422,7 @@ impl SimpleFunctionImpl { } } -impl fmt::Debug for SimpleFunctionImpl { +impl Debug for SimpleFunctionImpl { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_tuple("SimpleFunctionImpl") .field(&(self.0 as *const ())) diff --git a/engine/src/lhs_types/array.rs b/engine/src/lhs_types/array.rs index b3620f00..5b32a529 100644 --- a/engine/src/lhs_types/array.rs +++ b/engine/src/lhs_types/array.rs @@ -641,7 +641,7 @@ mod tests { #[test] fn test_size_of_array() { - assert_eq!(std::mem::size_of::>(), 32); + assert_eq!(size_of::>(), 32); } #[test] diff --git a/engine/src/lhs_types/bytes.rs b/engine/src/lhs_types/bytes.rs index 0ebf1f69..48e455f5 100644 --- a/engine/src/lhs_types/bytes.rs +++ b/engine/src/lhs_types/bytes.rs @@ -13,7 +13,7 @@ pub enum Bytes<'a> { Owned(Box<[u8]>), } -impl<'a> Bytes<'a> { +impl Bytes<'_> { /// Clones self into a fully owned byte string. #[inline] pub fn to_owned(&self) -> Bytes<'static> { diff --git a/engine/src/lhs_types/map.rs b/engine/src/lhs_types/map.rs index 1a26b499..8c146dee 100644 --- a/engine/src/lhs_types/map.rs +++ b/engine/src/lhs_types/map.rs @@ -729,7 +729,7 @@ mod tests { #[test] fn test_size_of_map() { - assert_eq!(std::mem::size_of::>(), 40); + assert_eq!(size_of::>(), 40); } #[test] diff --git a/engine/src/list_matcher.rs b/engine/src/list_matcher.rs index 2de813ed..6decaea1 100644 --- a/engine/src/list_matcher.rs +++ b/engine/src/list_matcher.rs @@ -13,10 +13,10 @@ pub trait ListDefinition: Debug + Sync + Send { /// /// This method is necessary to support deserialization of lists during the /// the deserialization of an `ExecutionContext`. - fn deserialize_matcher<'de>( + fn deserialize_matcher( &self, ty: Type, - deserializer: &mut dyn erased_serde::Deserializer<'de>, + deserializer: &mut dyn erased_serde::Deserializer<'_>, ) -> Result, erased_serde::Error>; /// Creates a new matcher object for this list. @@ -86,10 +86,10 @@ pub struct AlwaysList {} pub struct AlwaysListMatcher {} impl ListDefinition for AlwaysList { - fn deserialize_matcher<'de>( + fn deserialize_matcher( &self, _: Type, - deserializer: &mut dyn erased_serde::Deserializer<'de>, + deserializer: &mut dyn erased_serde::Deserializer<'_>, ) -> Result, erased_serde::Error> { let matcher = erased_serde::deserialize::(deserializer)?; Ok(Box::new(matcher)) @@ -117,10 +117,10 @@ pub struct NeverList {} pub struct NeverListMatcher {} impl ListDefinition for NeverList { - fn deserialize_matcher<'de>( + fn deserialize_matcher( &self, _: Type, - deserializer: &mut dyn erased_serde::Deserializer<'de>, + deserializer: &mut dyn erased_serde::Deserializer<'_>, ) -> Result, erased_serde::Error> { let matcher = erased_serde::deserialize::(deserializer)?; Ok(Box::new(matcher)) diff --git a/engine/src/rhs_types/bytes.rs b/engine/src/rhs_types/bytes.rs index 7ecefb21..0212eb6c 100644 --- a/engine/src/rhs_types/bytes.rs +++ b/engine/src/rhs_types/bytes.rs @@ -48,7 +48,7 @@ impl Serialize for BytesExpr { S: Serializer, { match self.format() { - BytesFormat::Quoted | BytesFormat::Raw(_) => match std::str::from_utf8(&self.data) { + BytesFormat::Quoted | BytesFormat::Raw(_) => match str::from_utf8(&self.data) { Ok(s) => s.serialize(serializer), Err(_) => self.data.serialize(serializer), }, @@ -116,7 +116,7 @@ impl Debug for BytesExpr { } match self.format { - BytesFormat::Quoted | BytesFormat::Raw(_) => match std::str::from_utf8(&self.data) { + BytesFormat::Quoted | BytesFormat::Raw(_) => match str::from_utf8(&self.data) { Ok(s) => s.fmt(f), Err(_) => fmt_raw(&self.data, f), }, diff --git a/engine/src/rhs_types/ip.rs b/engine/src/rhs_types/ip.rs index b1597958..12484191 100644 --- a/engine/src/rhs_types/ip.rs +++ b/engine/src/rhs_types/ip.rs @@ -83,7 +83,7 @@ impl Lex<'_> for IpRange { } }) } else { - IpRange::Cidr(cidr::IpCidr::from_str(chunk).map_err(|err| { + IpRange::Cidr(IpCidr::from_str(chunk).map_err(|err| { let split_pos = chunk.find('/').unwrap_or(chunk.len()); let err_span = match err { NetworkParseError::AddrParseError(_) | NetworkParseError::InvalidHostPart => { diff --git a/engine/src/scheme.rs b/engine/src/scheme.rs index d98b1364..952a8047 100644 --- a/engine/src/scheme.rs +++ b/engine/src/scheme.rs @@ -822,7 +822,7 @@ impl<'de> Deserialize<'de> for Scheme { impl<'de> Visitor<'de> for FieldMapVisitor { type Value = SchemeBuilder; - fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + fn expecting(&self, formatter: &mut Formatter<'_>) -> fmt::Result { formatter.write_str("a wirefilter scheme") } diff --git a/engine/src/types.rs b/engine/src/types.rs index d6466481..03b031f9 100644 --- a/engine/src/types.rs +++ b/engine/src/types.rs @@ -53,7 +53,7 @@ impl From for ExpectedType { } } -impl std::fmt::Display for ExpectedType { +impl fmt::Display for ExpectedType { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { ExpectedType::Array => write!(f, "Array<_>"), @@ -74,9 +74,9 @@ impl ExpectedTypeList { } } -impl fmt::Debug for ExpectedTypeList { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Debug::fmt(&self.0, f) +impl Debug for ExpectedTypeList { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.0, f) } } @@ -101,8 +101,8 @@ impl> From for ExpectedTypeList { } } -impl std::fmt::Display for ExpectedTypeList { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for ExpectedTypeList { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self.0.len() { 0 => unreachable!(), 1 => write!(f, "{}", self.0.first().unwrap()), @@ -263,7 +263,7 @@ macro_rules! declare_types { } } - impl<'i> LexWith<'i, Type> for RhsValue { + impl LexWith<'_, Type> for RhsValue { fn lex_with(input: &str, ty: Type) -> LexResult<'_, Self> { Ok(match ty { $(replace_underscore!($name $(($val_ty))?) => { @@ -274,7 +274,7 @@ macro_rules! declare_types { } } - impl<'a> PartialOrd for LhsValue<'a> { + impl PartialOrd for LhsValue<'_> { fn partial_cmp(&self, other: &RhsValue) -> Option { match (self, other) { $((LhsValue::$name(lhs), RhsValue::$name(rhs)) => { @@ -285,7 +285,7 @@ macro_rules! declare_types { } } - $(impl<'a> TryFrom for $rhs_ty { + $(impl TryFrom for $rhs_ty { type Error = TypeMismatchError; fn try_from(value: RhsValue) -> Result<$rhs_ty, TypeMismatchError> { @@ -380,7 +380,7 @@ macro_rules! declare_types { } } - impl<'i> LexWith<'i, Type> for RhsValues { + impl LexWith<'_, Type> for RhsValues { fn lex_with(input: &str, ty: Type) -> LexResult<'_, Self> { Ok(match ty { $(replace_underscore!($name $(($val_ty))?) => { @@ -422,8 +422,8 @@ impl Type { } } -impl std::fmt::Display for Type { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for Type { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::Bool => write!(f, "Bool"), Self::Bytes => write!(f, "Bytes"), @@ -809,7 +809,7 @@ impl<'de> DeserializeSeed<'de> for LhsValueSeed<'_> { D: Deserializer<'de>, { match self.0 { - Type::Ip => Ok(LhsValue::Ip(std::net::IpAddr::deserialize(deserializer)?)), + Type::Ip => Ok(LhsValue::Ip(IpAddr::deserialize(deserializer)?)), Type::Int => Ok(LhsValue::Int(i64::deserialize(deserializer)?)), Type::Bool => Ok(LhsValue::Bool(bool::deserialize(deserializer)?)), Type::Bytes => Ok(LhsValue::Bytes(Bytes::deserialize(deserializer)?)), @@ -1174,5 +1174,5 @@ fn test_type_deserialize() { #[test] fn test_size_of_lhs_value() { - assert_eq!(std::mem::size_of::>(), 48); + assert_eq!(size_of::>(), 48); } diff --git a/ffi/src/cstring.rs b/ffi/src/cstring.rs index ddb18ab3..9017dbf6 100644 --- a/ffi/src/cstring.rs +++ b/ffi/src/cstring.rs @@ -50,19 +50,19 @@ impl CString { } impl io::Write for CString { - fn write(&mut self, buf: &[u8]) -> std::io::Result { + fn write(&mut self, buf: &[u8]) -> io::Result { self.append(buf); Ok(buf.len()) } #[inline] - fn flush(&mut self) -> std::io::Result<()> { + fn flush(&mut self) -> io::Result<()> { Ok(()) } } impl fmt::Write for CString { - fn write_str(&mut self, s: &str) -> Result<(), std::fmt::Error> { + fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { self.append(s.as_bytes()); Ok(()) } diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 321bac5a..bd832489 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -218,7 +218,7 @@ pub enum Status { /// Returns a pointer to the last error string if there was one or NULL. #[unsafe(no_mangle)] pub extern "C" fn wirefilter_get_last_error() -> *const c_char { - crate::LAST_ERROR.with_borrow(|last_error| last_error.as_c_str()) + LAST_ERROR.with_borrow(|last_error| last_error.as_c_str()) } /// Clears the last error string if there was one. @@ -227,7 +227,7 @@ pub extern "C" fn wirefilter_get_last_error() -> *const c_char { /// until another error is written to it. #[unsafe(no_mangle)] pub extern "C" fn wirefilter_clear_last_error() { - crate::LAST_ERROR.with_borrow_mut(|last_error| { + LAST_ERROR.with_borrow_mut(|last_error| { last_error.clear(); }); } From d789065e85ebc303f1a2b3b9ffdde1eb2deff53b Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Thu, 26 Feb 2026 15:25:09 +0000 Subject: [PATCH 5/5] Manual fixes --- engine/src/ast/field_expr.rs | 10 +++------- engine/src/ast/function_expr.rs | 13 +++++-------- engine/src/ast/index_expr.rs | 6 ++---- engine/src/functions/mod.rs | 1 - engine/src/range_set.rs | 1 - engine/src/scheme.rs | 2 -- engine/src/types.rs | 3 ++- ffi/src/lib.rs | 8 ++++---- 8 files changed, 16 insertions(+), 28 deletions(-) diff --git a/engine/src/ast/field_expr.rs b/engine/src/ast/field_expr.rs index c60646a7..f7a6aa02 100644 --- a/engine/src/ast/field_expr.rs +++ b/engine/src/ast/field_expr.rs @@ -794,9 +794,8 @@ impl Expr for ComparisonExpr { #[expect(clippy::bool_assert_comparison)] mod tests { use super::*; - use crate::ast::function_expr::{FunctionCallArgExpr, FunctionCallExpr}; + use crate::ast::function_expr::FunctionCallArgExpr; use crate::ast::logical_expr::LogicalExpr; - use crate::execution_context::ExecutionContext; use crate::functions::{ FunctionArgKind, FunctionArgs, FunctionDefinition, FunctionDefinitionContext, FunctionParam, FunctionParamError, SimpleFunctionDefinition, SimpleFunctionImpl, @@ -805,17 +804,14 @@ mod tests { use crate::lhs_types::{Array, Map}; use crate::list_matcher::{ListDefinition, ListMatcher}; use crate::rhs_types::{IpRange, RegexFormat}; - use crate::scheme::{FieldIndex, IndexAccessError, Scheme}; + use crate::scheme::{FieldIndex, IndexAccessError}; use crate::types::ExpectedType; use crate::{ - BytesFormat, FieldRef, LhsValue, ParserSettings, SchemeBuilder, SimpleFunctionArgKind, - TypedMap, + BytesFormat, FieldRef, ParserSettings, SchemeBuilder, SimpleFunctionArgKind, TypedMap, }; use cidr::IpCidr; use serde::Deserialize; - use std::convert::TryFrom; use std::iter::once; - use std::net::IpAddr; use std::sync::LazyLock; fn any_function<'a>(args: FunctionArgs<'_, 'a>) -> Option> { diff --git a/engine/src/ast/function_expr.rs b/engine/src/ast/function_expr.rs index 3a254807..fa1bb1d9 100644 --- a/engine/src/ast/function_expr.rs +++ b/engine/src/ast/function_expr.rs @@ -509,18 +509,15 @@ impl<'i> LexWith<'i, &FilterParser<'_>> for FunctionCallExpr { #[cfg(test)] mod tests { use super::*; - use crate::SimpleFunctionArgKind; - use crate::ast::field_expr::{ComparisonExpr, ComparisonOpExpr, IdentifierExpr, OrderingOp}; - use crate::ast::logical_expr::{LogicalExpr, LogicalOp, ParenthesizedExpr}; - use crate::ast::parse::FilterParser; + use crate::ast::field_expr::{ComparisonOpExpr, IdentifierExpr, OrderingOp}; + use crate::ast::logical_expr::{LogicalOp, ParenthesizedExpr}; use crate::functions::{ - FunctionArgKind, FunctionArgKindMismatchError, FunctionArgs, SimpleFunctionDefinition, - SimpleFunctionImpl, SimpleFunctionOptParam, SimpleFunctionParam, + FunctionArgKind, FunctionArgKindMismatchError, SimpleFunctionArgKind, + SimpleFunctionDefinition, SimpleFunctionImpl, SimpleFunctionOptParam, SimpleFunctionParam, }; use crate::rhs_types::{BytesExpr, BytesFormat}; use crate::scheme::{FieldIndex, IndexAccessError, Scheme}; - use crate::types::{RhsValues, Type, TypeMismatchError}; - use std::convert::TryFrom; + use crate::types::{RhsValues, TypeMismatchError}; use std::sync::LazyLock; fn any_function<'a>(args: FunctionArgs<'_, 'a>) -> Option> { diff --git a/engine/src/ast/index_expr.rs b/engine/src/ast/index_expr.rs index ea26571e..6fa5651e 100644 --- a/engine/src/ast/index_expr.rs +++ b/engine/src/ast/index_expr.rs @@ -525,11 +525,9 @@ impl<'a> Iterator for MapEachIterator<'a, '_> { #[cfg(test)] mod tests { use super::*; - use crate::ast::field_expr::IdentifierExpr; use crate::{ - Array, FieldIndex, FilterParser, FunctionArgs, FunctionCallArgExpr, FunctionCallExpr, - Scheme, SchemeBuilder, SimpleFunctionArgKind, SimpleFunctionDefinition, SimpleFunctionImpl, - SimpleFunctionParam, + FunctionArgs, FunctionCallArgExpr, FunctionCallExpr, Scheme, SchemeBuilder, + SimpleFunctionArgKind, SimpleFunctionDefinition, SimpleFunctionImpl, SimpleFunctionParam, }; use std::sync::LazyLock; diff --git a/engine/src/functions/mod.rs b/engine/src/functions/mod.rs index 9b9db98b..c5bd7437 100644 --- a/engine/src/functions/mod.rs +++ b/engine/src/functions/mod.rs @@ -11,7 +11,6 @@ use crate::types::{ ExpectedType, ExpectedTypeList, GetType, LhsValue, RhsValue, Type, TypeMismatchError, }; use std::any::Any; -use std::convert::TryFrom; use std::fmt::{self, Debug}; use std::iter::once; use thiserror::Error; diff --git a/engine/src/range_set.rs b/engine/src/range_set.rs index e024f787..7b3aeb76 100644 --- a/engine/src/range_set.rs +++ b/engine/src/range_set.rs @@ -1,6 +1,5 @@ use std::borrow::Borrow; use std::cmp::Ordering; -use std::iter::FromIterator; use std::ops::RangeInclusive; /// RangeSet provides a set-like interface that allows to search for items while diff --git a/engine/src/scheme.rs b/engine/src/scheme.rs index 952a8047..e2909df1 100644 --- a/engine/src/scheme.rs +++ b/engine/src/scheme.rs @@ -10,10 +10,8 @@ use serde::ser::SerializeMap; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::collections::HashMap; use std::collections::hash_map::Entry; -use std::convert::TryFrom; use std::fmt::{self, Debug, Formatter}; use std::hash::{Hash, Hasher}; -use std::iter::Iterator; use std::sync::Arc; use thiserror::Error; diff --git a/engine/src/types.rs b/engine/src/types.rs index 03b031f9..49f3b798 100644 --- a/engine/src/types.rs +++ b/engine/src/types.rs @@ -9,7 +9,6 @@ use serde::de::{DeserializeSeed, Deserializer}; use serde::{Deserialize, Serialize, Serializer}; use std::cmp::Ordering; use std::collections::BTreeSet; -use std::convert::TryFrom; use std::fmt::{self, Debug, Formatter}; use std::iter::once; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; @@ -189,6 +188,7 @@ macro_rules! declare_types { $($(# $vattrs)* $variant($ty),)* } + #[allow(single_use_lifetimes)] impl $(<$lt>)* GetType for $name $(<$lt>)* { fn get_type(&self) -> Type { match self { @@ -197,6 +197,7 @@ macro_rules! declare_types { } } + #[allow(single_use_lifetimes)] impl $(<$lt>)* Debug for $name $(<$lt>)* { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index bd832489..136bb151 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -7,7 +7,6 @@ use libc::c_char; use num_enum::{IntoPrimitive, TryFromPrimitive}; use serde::de::DeserializeSeed; use std::cell::RefCell; -use std::convert::TryFrom; use std::hash::Hasher; use std::io::{self, Write}; use std::net::IpAddr; @@ -137,6 +136,7 @@ macro_rules! wrap_type { } } + #[allow(single_use_lifetimes)] impl$(<$ffi_lt>)? DerefMut for $ffi$(<$ffi_lt>)? { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 @@ -498,8 +498,8 @@ pub extern "C" fn wirefilter_serialize_type_to_json(ty: CType) -> SerializingRes } #[unsafe(no_mangle)] -pub extern "C" fn wirefilter_create_execution_context<'e, 's: 'e>( - scheme: &'s Scheme, +pub extern "C" fn wirefilter_create_execution_context<'e>( + scheme: &Scheme, ) -> Box> { Box::new(ExecutionContext(wirefilter::ExecutionContext::new(scheme))) } @@ -888,7 +888,7 @@ mod ffi_test { wirefilter_build_scheme(builder) } - fn create_execution_context<'e, 's: 'e>(scheme: &'s Scheme) -> Box> { + fn create_execution_context<'e>(scheme: &Scheme) -> Box> { let mut exec_context = wirefilter_create_execution_context(scheme); let invalid_key = &b"\xc3\x28"[..];