diff --git a/build.rs b/build.rs index a8b6fc44e1..501efc25a8 100644 --- a/build.rs +++ b/build.rs @@ -32,7 +32,7 @@ fn read_grok_patterns() { fs::read_dir(Path::new("src/datadog/grok/patterns")) .expect("can't read 'patterns' dir") .filter_map(|path| File::open(path.expect("can't read 'patterns' dir").path()).ok()) - .flat_map(|f| BufReader::new(f).lines().filter_map(|l| l.ok())) + .flat_map(|f| BufReader::new(f).lines().map_while(Result::ok)) .filter(|line| !line.starts_with('#') && !line.trim().is_empty()) .for_each(|line| { let (key, value) = line.split_at( diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f238a797e8..08e602710e 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.69.0" +channel = "1.71.1" profile = "default" diff --git a/src/compiler/value/arithmetic.rs b/src/compiler/value/arithmetic.rs index a318dea112..356317a202 100644 --- a/src/compiler/value/arithmetic.rs +++ b/src/compiler/value/arithmetic.rs @@ -1,6 +1,7 @@ -#![deny(clippy::integer_arithmetic)] +#![deny(clippy::arithmetic_side_effects)] use std::collections::BTreeMap; +use std::ops::{Add, Mul, Rem, Sub}; use crate::value::Value; use bytes::{BufMut, Bytes, BytesMut}; @@ -79,7 +80,10 @@ impl VrlValueArithmetic for Value { let rhv = rhs.try_into_i64().map_err(|_| err())?; i64::wrapping_mul(lhv, rhv).into() } - Value::Float(lhv) => (lhv * rhs.try_into_f64().map_err(|_| err())?).into(), + Value::Float(lhv) => { + let rhs = rhs.try_into_f64().map_err(|_| err())?; + lhv.mul(rhs).into() + } Value::Bytes(lhv) if rhs.is_integer() => { Bytes::from(lhv.repeat(as_usize(rhs.try_integer()?))).into() } @@ -118,14 +122,15 @@ impl VrlValueArithmetic for Value { .map_err(|_| ValueError::Add(Kind::integer(), rhs.kind()))?; i64::wrapping_add(lhs, rhv).into() } - (Value::Float(lhs), rhs) => (lhs - + rhs + (Value::Float(lhs), rhs) => { + let rhs = rhs .try_into_f64() - .map_err(|_| ValueError::Add(Kind::float(), rhs.kind()))?) - .into(), + .map_err(|_| ValueError::Add(Kind::float(), rhs.kind()))?; + lhs.add(rhs).into() + } (lhs @ Value::Bytes(_), Value::Null) => lhs, (Value::Bytes(lhs), Value::Bytes(rhs)) => { - #[allow(clippy::integer_arithmetic)] + #[allow(clippy::arithmetic_side_effects)] let mut value = BytesMut::with_capacity(lhs.len() + rhs.len()); value.put(lhs); value.put(rhs); @@ -150,7 +155,10 @@ impl VrlValueArithmetic for Value { let rhv = rhs.try_into_i64().map_err(|_| err())?; i64::wrapping_sub(lhv, rhv).into() } - Value::Float(lhv) => (lhv - rhs.try_into_f64().map_err(|_| err())?).into(), + Value::Float(lhv) => { + let rhv = rhs.try_into_f64().map_err(|_| err())?; + lhv.sub(rhv).into() + } _ => return Err(err()), }; @@ -212,7 +220,10 @@ impl VrlValueArithmetic for Value { let rhv = rhs.try_into_i64().map_err(|_| err())?; i64::wrapping_rem(lhv, rhv).into() } - Value::Float(lhv) => (lhv % rhs.try_into_f64().map_err(|_| err())?).into(), + Value::Float(lhv) => { + let rhv = rhs.try_into_f64().map_err(|_| err())?; + lhv.rem(rhv).into() + } _ => return Err(err()), }; diff --git a/src/stdlib/encode_json.rs b/src/stdlib/encode_json.rs index 74f8d8362c..299182ce20 100644 --- a/src/stdlib/encode_json.rs +++ b/src/stdlib/encode_json.rs @@ -1,6 +1,6 @@ use crate::compiler::prelude::*; -fn encode_json(value: Value, pretty: bool) -> Resolved { +fn encode_json(value: Value, pretty: bool) -> Value { // With `vrl::Value` it should not be possible to get `Err`. let result = if pretty { @@ -10,7 +10,7 @@ fn encode_json(value: Value, pretty: bool) -> Resolved { }; match result { - Ok(value) => Ok(value.into()), + Ok(value) => value.into(), Err(error) => unreachable!("unable encode to json: {}", error), } } @@ -81,7 +81,7 @@ impl FunctionExpression for EncodeJsonFn { Some(pretty) => pretty.resolve(ctx)?.try_boolean()?, None => false, }; - encode_json(value, pretty) + Ok(encode_json(value, pretty)) } fn type_def(&self, _: &state::TypeState) -> TypeDef { diff --git a/src/stdlib/match_datadog_query.rs b/src/stdlib/match_datadog_query.rs index b6e6074d46..c18459f687 100644 --- a/src/stdlib/match_datadog_query.rs +++ b/src/stdlib/match_datadog_query.rs @@ -64,7 +64,7 @@ impl Function for MatchDatadogQuery { // Build the matcher function that accepts a VRL event value. This will parse the `node` // at boot-time and return a boxed func that contains just the logic required to match a // VRL `Value` against the Datadog Search Syntax literal. - let filter = build_matcher(&node, &VrlFilter::default()); + let filter = build_matcher(&node, &VrlFilter); Ok(MatchDatadogQueryFn { value, filter }.as_expr()) }