From 49060a2387a7787b153de6ff8c8f3d56bd1ce1e7 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 16:36:14 -0500 Subject: [PATCH 1/9] chore(dev): deny cast_sign_loss --- src/stdlib/encode_gzip.rs | 4 +++- src/stdlib/encode_zlib.rs | 3 ++- src/stdlib/find.rs | 4 ++-- src/stdlib/format_int.rs | 16 ++++++++-------- src/stdlib/format_number.rs | 2 +- src/stdlib/mod.rs | 1 - src/stdlib/parse_etld.rs | 2 +- src/stdlib/parse_int.rs | 2 +- src/stdlib/parse_json.rs | 3 ++- src/stdlib/random_bytes.rs | 8 +++++--- src/stdlib/replace.rs | 14 +++++++++----- src/stdlib/replace_with.rs | 2 +- src/stdlib/slice.rs | 1 + src/stdlib/split.rs | 2 +- src/stdlib/truncate.rs | 6 +++++- src/stdlib/uuid_v7.rs | 1 + 16 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/stdlib/encode_gzip.rs b/src/stdlib/encode_gzip.rs index 3bba7e3bd..79a82b180 100644 --- a/src/stdlib/encode_gzip.rs +++ b/src/stdlib/encode_gzip.rs @@ -11,7 +11,9 @@ fn encode_gzip(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - let level = value.try_integer()? as u32; + let level = value.try_integer()?; + let level = u32::try_from(level).map_err(|e| e.to_string())?; + if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); } diff --git a/src/stdlib/encode_zlib.rs b/src/stdlib/encode_zlib.rs index 97f10729f..b0da2a6eb 100644 --- a/src/stdlib/encode_zlib.rs +++ b/src/stdlib/encode_zlib.rs @@ -11,7 +11,8 @@ fn encode_zlib(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - let level = value.try_integer()? as u32; + let level = value.try_integer()?; + let level = u32::try_from(level).map_err(|e| e.to_string())?; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); } diff --git a/src/stdlib/find.rs b/src/stdlib/find.rs index 8e9bc0b3c..1bddcbbfd 100644 --- a/src/stdlib/find.rs +++ b/src/stdlib/find.rs @@ -5,8 +5,8 @@ fn find(value: Value, pattern: Value, from: Option) -> Resolved { let from = match from { Some(value) => value.try_integer()?, None => 0, - } as usize; - + }; + let from = usize::try_from(from).map_err(|e| e.to_string())?; Ok(FindFn::find(value, pattern, from)? .map_or(Value::Integer(-1), |value| Value::Integer(value as i64))) } diff --git a/src/stdlib/format_int.rs b/src/stdlib/format_int.rs index fe1755de4..1dc9e981d 100644 --- a/src/stdlib/format_int.rs +++ b/src/stdlib/format_int.rs @@ -1,6 +1,6 @@ -use std::collections::VecDeque; - use crate::compiler::prelude::*; +use std::collections::VecDeque; +use std::num::TryFromIntError; fn format_int(value: Value, base: Option) -> Resolved { let value = value.try_integer()?; @@ -14,11 +14,11 @@ fn format_int(value: Value, base: Option) -> Resolved { .into()); } - value as u32 + u32::try_from(value).map_err(|e| e.to_string())? } None => 10u32, }; - let converted = format_radix(value, base); + let converted = format_radix(value, base).map_err(|e| e.to_string())?; Ok(converted.into()) } @@ -106,13 +106,13 @@ impl FunctionExpression for FormatIntFn { // Formats x in the provided radix // // Panics if radix is < 2 or > 36 -fn format_radix(x: i64, radix: u32) -> String { +fn format_radix(x: i64, radix: u32) -> Result { let mut result: VecDeque = VecDeque::new(); let (mut x, negative) = if x < 0 { - (-x as u64, true) + (u64::try_from(-x)?, true) } else { - (x as u64, false) + (u64::try_from(x)?, false) }; loop { @@ -129,7 +129,7 @@ fn format_radix(x: i64, radix: u32) -> String { result.push_front('-'); } - result.into_iter().collect() + Ok(result.into_iter().collect()) } #[cfg(test)] diff --git a/src/stdlib/format_number.rs b/src/stdlib/format_number.rs index 57cb18911..358a0e99c 100644 --- a/src/stdlib/format_number.rs +++ b/src/stdlib/format_number.rs @@ -41,7 +41,7 @@ fn format_number( match scale { Some(0) => parts.truncate(1), Some(i) => { - let i = i as usize; + let i = usize::try_from(i).map_err(|e| e.to_string())?; if parts.len() == 1 { parts.push(String::new()); diff --git a/src/stdlib/mod.rs b/src/stdlib/mod.rs index 728debb3d..f412f912c 100644 --- a/src/stdlib/mod.rs +++ b/src/stdlib/mod.rs @@ -3,7 +3,6 @@ deprecated, clippy::cast_possible_truncation, // allowed in initial deny commit clippy::cast_precision_loss, // allowed in initial deny commit - clippy::cast_sign_loss, // allowed in initial deny commit clippy::needless_pass_by_value, // allowed in initial deny commit )] diff --git a/src/stdlib/parse_etld.rs b/src/stdlib/parse_etld.rs index 78cb23d02..edb5644c0 100644 --- a/src/stdlib/parse_etld.rs +++ b/src/stdlib/parse_etld.rs @@ -137,7 +137,7 @@ impl FunctionExpression for ParseEtldFn { let plus_parts = match self.plus_parts.resolve(ctx)?.try_integer()? { x if x < 0 => 0, - x => x as usize, + x => usize::try_from(x).map_err(|e| e.to_string())?, }; let suffix_result = if let Some(list) = &self.psl { diff --git a/src/stdlib/parse_int.rs b/src/stdlib/parse_int.rs index 41e7da3b3..ba434b2a4 100644 --- a/src/stdlib/parse_int.rs +++ b/src/stdlib/parse_int.rs @@ -12,7 +12,7 @@ fn parse_int(value: Value, base: Option) -> Resolved { ) .into()); } - (base as u32, 0) + (u32::try_from(base).map_err(|e| e.to_string())?, 0) } None => match string.chars().next() { Some('0') => match string.chars().nth(1) { diff --git a/src/stdlib/parse_json.rs b/src/stdlib/parse_json.rs index 348c1d33f..62ca2ad7f 100644 --- a/src/stdlib/parse_json.rs +++ b/src/stdlib/parse_json.rs @@ -84,6 +84,7 @@ fn parse_layer(value: &RawValue, remaining_depth: u8) -> std::result::Result ExpressionResult { let res = value.try_integer()?; + let res = u8::try_from(res).map_err(|e| e.to_string())?; // The lower cap is 1 because it is pointless to use anything lower, // because 'data = parse_json!(.message, max_depth: 0)' equals to 'data = .message'. @@ -91,7 +92,7 @@ fn validate_depth(value: Value) -> ExpressionResult { // The upper cap is 128 because serde_json has the same recursion limit by default. // https://github.com/serde-rs/json/blob/4d57ebeea8d791b8a51c229552d2d480415d00e6/json/src/de.rs#L111 if (1..=128).contains(&res) { - Ok(res as u8) + Ok(res) } else { Err(ExpressionError::from(format!( "max_depth value should be greater than 0 and less than 128, got {res}" diff --git a/src/stdlib/random_bytes.rs b/src/stdlib/random_bytes.rs index e6403a1df..ab45c0243 100644 --- a/src/stdlib/random_bytes.rs +++ b/src/stdlib/random_bytes.rs @@ -60,15 +60,17 @@ impl Function for RandomBytes { } } -fn get_length(value: Value) -> std::result::Result { - let length = value.try_integer().expect("length must be an integer"); +fn get_length(value: Value) -> Result { + let length = value + .try_integer() + .map_err(|_| "Couldn't convert value to integer")?; if length < 0 { return Err(LENGTH_TOO_SMALL_ERR); } if length > MAX_LENGTH { return Err(LENGTH_TOO_LARGE_ERR); } - Ok(length as usize) + usize::try_from(length).map_err(|_| "i64 to usize conversion failed") } #[derive(Debug, Clone)] diff --git a/src/stdlib/replace.rs b/src/stdlib/replace.rs index b18c9dd86..0a79f8b6f 100644 --- a/src/stdlib/replace.rs +++ b/src/stdlib/replace.rs @@ -8,7 +8,10 @@ fn replace(value: Value, with_value: Value, count: Value, pattern: Value) -> Res Value::Bytes(bytes) => { let pattern = String::from_utf8_lossy(&bytes); let replaced = match count { - i if i > 0 => value.replacen(pattern.as_ref(), &with, i as usize), + i if i > 0 => { + let i = usize::try_from(i).map_err(|e| e.to_string())?; + value.replacen(pattern.as_ref(), &with, i) + } i if i < 0 => value.replace(pattern.as_ref(), &with), _ => value.into_owned(), }; @@ -17,10 +20,11 @@ fn replace(value: Value, with_value: Value, count: Value, pattern: Value) -> Res } Value::Regex(regex) => { let replaced = match count { - i if i > 0 => Bytes::copy_from_slice( - regex.replacen(&value, i as usize, with.as_ref()).as_bytes(), - ) - .into(), + i if i > 0 => { + let i = usize::try_from(i).map_err(|e| e.to_string())?; + Bytes::copy_from_slice(regex.replacen(&value, i, with.as_ref()).as_bytes()) + .into() + } i if i < 0 => { Bytes::copy_from_slice(regex.replace_all(&value, with.as_ref()).as_bytes()) .into() diff --git a/src/stdlib/replace_with.rs b/src/stdlib/replace_with.rs index 0d452e5c9..4eea32c73 100644 --- a/src/stdlib/replace_with.rs +++ b/src/stdlib/replace_with.rs @@ -16,7 +16,7 @@ where { let haystack = value.try_bytes_utf8_lossy()?; let count = match count.try_integer()? { - i if i > 0 => i as usize, + i if i > 0 => usize::try_from(i).map_err(|e| e.to_string())?, i if i < 0 => 0, // this is when i == 0 _ => return Ok(value), diff --git a/src/stdlib/slice.rs b/src/stdlib/slice.rs index 7dba88238..5b66f027f 100644 --- a/src/stdlib/slice.rs +++ b/src/stdlib/slice.rs @@ -3,6 +3,7 @@ use std::ops::Range; use crate::compiler::prelude::*; #[allow(clippy::cast_possible_wrap)] +#[allow(clippy::cast_sign_loss)] fn slice(start: i64, end: Option, value: Value) -> Resolved { let range = |len: i64| -> ExpressionResult> { let start = match start { diff --git a/src/stdlib/split.rs b/src/stdlib/split.rs index b907f0398..b10f86671 100644 --- a/src/stdlib/split.rs +++ b/src/stdlib/split.rs @@ -4,7 +4,7 @@ fn split(value: Value, limit: Value, pattern: Value) -> Resolved { let string = value.try_bytes_utf8_lossy()?; let limit = match limit.try_integer()? { x if x < 0 => 0, - x => x as usize, + x => usize::try_from(x).map_err(|e| e.to_string())?, }; match pattern { Value::Regex(pattern) => Ok(pattern diff --git a/src/stdlib/truncate.rs b/src/stdlib/truncate.rs index a7cd0be4b..d14189cc9 100644 --- a/src/stdlib/truncate.rs +++ b/src/stdlib/truncate.rs @@ -3,7 +3,11 @@ use crate::compiler::prelude::*; fn truncate(value: Value, limit: Value, suffix: Value) -> Resolved { let mut value = value.try_bytes_utf8_lossy()?.into_owned(); let limit = limit.try_integer()?; - let limit = if limit < 0 { 0 } else { limit as usize }; + let limit = if limit < 0 { + 0 + } else { + usize::try_from(limit).map_err(|e| e.to_string())? + }; let suffix = suffix.try_bytes_utf8_lossy()?.to_string(); let pos = if let Some((pos, chr)) = value.char_indices().take(limit).last() { // char_indices gives us the starting position of the character at limit, diff --git a/src/stdlib/uuid_v7.rs b/src/stdlib/uuid_v7.rs index 871d5dbad..4f51c9ff8 100644 --- a/src/stdlib/uuid_v7.rs +++ b/src/stdlib/uuid_v7.rs @@ -3,6 +3,7 @@ use bytes::Bytes; use chrono::{DateTime, Utc}; use uuid::{timestamp::Timestamp, NoContext}; +#[allow(clippy::cast_sign_loss)] fn uuid_v7(timestamp: Option) -> Resolved { let utc_timestamp: DateTime = if let Some(timestamp) = timestamp { timestamp.try_timestamp()? From 8ff0f3d204acee1dba1ff5b82728626591fae769 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 16:53:06 -0500 Subject: [PATCH 2/9] deny clippy::cast_precision_loss --- src/stdlib/match_datadog_query.rs | 1 + src/stdlib/mod.rs | 1 - src/stdlib/parse_influxdb.rs | 1 + src/stdlib/to_float.rs | 1 + src/stdlib/util.rs | 1 + src/value/value/serde.rs | 2 +- 6 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/stdlib/match_datadog_query.rs b/src/stdlib/match_datadog_query.rs index 9a8e160e6..8e6efc1e0 100644 --- a/src/stdlib/match_datadog_query.rs +++ b/src/stdlib/match_datadog_query.rs @@ -301,6 +301,7 @@ impl Filter for VrlFilter { }) } + #[allow(clippy::cast_precision_loss)] //TODO evaluate removal options fn compare( &self, field: Field, diff --git a/src/stdlib/mod.rs b/src/stdlib/mod.rs index f412f912c..adadd4b93 100644 --- a/src/stdlib/mod.rs +++ b/src/stdlib/mod.rs @@ -2,7 +2,6 @@ #![allow( deprecated, clippy::cast_possible_truncation, // allowed in initial deny commit - clippy::cast_precision_loss, // allowed in initial deny commit clippy::needless_pass_by_value, // allowed in initial deny commit )] diff --git a/src/stdlib/parse_influxdb.rs b/src/stdlib/parse_influxdb.rs index af12fa548..02b179379 100644 --- a/src/stdlib/parse_influxdb.rs +++ b/src/stdlib/parse_influxdb.rs @@ -6,6 +6,7 @@ use influxdb_line_protocol::{FieldValue, ParsedLine}; use crate::compiler::prelude::*; use crate::{btreemap, value}; +#[allow(clippy::cast_precision_loss)] //TODO evaluate removal options fn influxdb_line_to_metrics(line: ParsedLine) -> Result, ExpressionError> { let ParsedLine { series, diff --git a/src/stdlib/to_float.rs b/src/stdlib/to_float.rs index 04fc6014e..0e4d1c225 100644 --- a/src/stdlib/to_float.rs +++ b/src/stdlib/to_float.rs @@ -7,6 +7,7 @@ pub(crate) fn bytes_to_float(bytes: Bytes) -> Resolved { .map_err(|e| e.to_string().into()) } +#[allow(clippy::cast_precision_loss)] //TODO evaluate removal options fn to_float(value: Value) -> Resolved { use Value::{Boolean, Bytes, Float, Integer, Null, Timestamp}; match value { diff --git a/src/stdlib/util.rs b/src/stdlib/util.rs index aee710755..61ba4487c 100644 --- a/src/stdlib/util.rs +++ b/src/stdlib/util.rs @@ -5,6 +5,7 @@ use crate::value::{KeyString, ObjectMap, Value}; /// Takes a function parameter so the exact rounding function (ceil, floor or round) /// can be specified. #[inline] +#[allow(clippy::cast_precision_loss)] //TODO evaluate removal options pub(crate) fn round_to_precision(num: f64, precision: i64, fun: F) -> f64 where F: Fn(f64) -> f64, diff --git a/src/value/value/serde.rs b/src/value/value/serde.rs index b5cfc27dc..e433a0ffc 100644 --- a/src/value/value/serde.rs +++ b/src/value/value/serde.rs @@ -107,7 +107,7 @@ impl<'de> Deserialize<'de> for Value { Ok(value.into()) } else { // TODO: Address this issue by providing a lossless conversion option. - #[allow(clippy::cast_precision_loss)] + #[allow(clippy::cast_precision_loss)] //TODO evaluate removal options let converted_value = value as f64; let wrapped_value = NotNan::new(converted_value).map_err(|_| { SerdeError::invalid_value( From ec9c234792338832d3955840e3f9a3e4069ac24a Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 17:03:13 -0500 Subject: [PATCH 3/9] start reverting breaking changes, should do it step by step --- src/stdlib/encode_gzip.rs | 5 ++--- src/stdlib/encode_zlib.rs | 4 ++-- src/stdlib/encode_zstd.rs | 1 + src/stdlib/find.rs | 5 +++-- src/stdlib/format_int.rs | 18 ++++++++++-------- src/stdlib/format_number.rs | 3 ++- src/stdlib/get.rs | 1 + src/stdlib/mod.rs | 1 - src/stdlib/remove.rs | 1 + src/stdlib/set.rs | 1 + src/stdlib/slice.rs | 1 + src/stdlib/to_int.rs | 1 + src/stdlib/uuid_v7.rs | 1 + 13 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/stdlib/encode_gzip.rs b/src/stdlib/encode_gzip.rs index 79a82b180..9a1ecc1d4 100644 --- a/src/stdlib/encode_gzip.rs +++ b/src/stdlib/encode_gzip.rs @@ -11,9 +11,8 @@ fn encode_gzip(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - let level = value.try_integer()?; - let level = u32::try_from(level).map_err(|e| e.to_string())?; - + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); } diff --git a/src/stdlib/encode_zlib.rs b/src/stdlib/encode_zlib.rs index b0da2a6eb..31558c6ee 100644 --- a/src/stdlib/encode_zlib.rs +++ b/src/stdlib/encode_zlib.rs @@ -11,8 +11,8 @@ fn encode_zlib(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - let level = value.try_integer()?; - let level = u32::try_from(level).map_err(|e| e.to_string())?; + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); } diff --git a/src/stdlib/encode_zstd.rs b/src/stdlib/encode_zstd.rs index 6d8209035..027a3cb8a 100644 --- a/src/stdlib/encode_zstd.rs +++ b/src/stdlib/encode_zstd.rs @@ -4,6 +4,7 @@ use nom::AsBytes; fn encode_zstd(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => 0, + #[allow(clippy::cast_possible_truncation)] //TODO evaluate removal options Some(value) => value.try_integer()? as i32, }; diff --git a/src/stdlib/find.rs b/src/stdlib/find.rs index 1bddcbbfd..fe657a1d3 100644 --- a/src/stdlib/find.rs +++ b/src/stdlib/find.rs @@ -2,11 +2,12 @@ use crate::compiler::prelude::*; #[allow(clippy::cast_possible_wrap)] fn find(value: Value, pattern: Value, from: Option) -> Resolved { + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options let from = match from { Some(value) => value.try_integer()?, None => 0, - }; - let from = usize::try_from(from).map_err(|e| e.to_string())?; + } as usize; + Ok(FindFn::find(value, pattern, from)? .map_or(Value::Integer(-1), |value| Value::Integer(value as i64))) } diff --git a/src/stdlib/format_int.rs b/src/stdlib/format_int.rs index 1dc9e981d..221b071a7 100644 --- a/src/stdlib/format_int.rs +++ b/src/stdlib/format_int.rs @@ -1,7 +1,8 @@ -use crate::compiler::prelude::*; use std::collections::VecDeque; -use std::num::TryFromIntError; +use crate::compiler::prelude::*; + +#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options fn format_int(value: Value, base: Option) -> Resolved { let value = value.try_integer()?; let base = match base { @@ -14,11 +15,11 @@ fn format_int(value: Value, base: Option) -> Resolved { .into()); } - u32::try_from(value).map_err(|e| e.to_string())? + value as u32 } None => 10u32, }; - let converted = format_radix(value, base).map_err(|e| e.to_string())?; + let converted = format_radix(value, base); Ok(converted.into()) } @@ -106,13 +107,14 @@ impl FunctionExpression for FormatIntFn { // Formats x in the provided radix // // Panics if radix is < 2 or > 36 -fn format_radix(x: i64, radix: u32) -> Result { +#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options +fn format_radix(x: i64, radix: u32) -> String { let mut result: VecDeque = VecDeque::new(); let (mut x, negative) = if x < 0 { - (u64::try_from(-x)?, true) + (-x as u64, true) } else { - (u64::try_from(x)?, false) + (x as u64, false) }; loop { @@ -129,7 +131,7 @@ fn format_radix(x: i64, radix: u32) -> Result { result.push_front('-'); } - Ok(result.into_iter().collect()) + result.into_iter().collect() } #[cfg(test)] diff --git a/src/stdlib/format_number.rs b/src/stdlib/format_number.rs index 358a0e99c..cc11f3202 100644 --- a/src/stdlib/format_number.rs +++ b/src/stdlib/format_number.rs @@ -41,7 +41,8 @@ fn format_number( match scale { Some(0) => parts.truncate(1), Some(i) => { - let i = usize::try_from(i).map_err(|e| e.to_string())?; + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + let i = i as usize; if parts.len() == 1 { parts.push(String::new()); diff --git a/src/stdlib/get.rs b/src/stdlib/get.rs index 9a10230d0..9fead3ded 100644 --- a/src/stdlib/get.rs +++ b/src/stdlib/get.rs @@ -1,6 +1,7 @@ use crate::compiler::prelude::*; use crate::path::{OwnedSegment, OwnedValuePath}; +#[allow(clippy::cast_possible_truncation)] // TODO consider removal options fn get(value: Value, value_path: Value) -> Resolved { let path = match value_path { Value::Array(array) => { diff --git a/src/stdlib/mod.rs b/src/stdlib/mod.rs index adadd4b93..87866e1bf 100644 --- a/src/stdlib/mod.rs +++ b/src/stdlib/mod.rs @@ -1,7 +1,6 @@ #![deny(warnings, clippy::pedantic)] #![allow( deprecated, - clippy::cast_possible_truncation, // allowed in initial deny commit clippy::needless_pass_by_value, // allowed in initial deny commit )] diff --git a/src/stdlib/remove.rs b/src/stdlib/remove.rs index 23014c25e..a5bb9f310 100644 --- a/src/stdlib/remove.rs +++ b/src/stdlib/remove.rs @@ -11,6 +11,7 @@ fn remove(path: Value, compact: Value, mut value: Value) -> Resolved { Value::Bytes(field) => { OwnedSegment::Field(String::from_utf8_lossy(&field).into()) } + #[allow(clippy::cast_possible_truncation)] //TODO evaluate removal options Value::Integer(index) => OwnedSegment::Index(index as isize), value => { return Err(format!( diff --git a/src/stdlib/set.rs b/src/stdlib/set.rs index 6ff311004..d9535764d 100644 --- a/src/stdlib/set.rs +++ b/src/stdlib/set.rs @@ -11,6 +11,7 @@ fn set(path: Value, mut value: Value, data: Value) -> Resolved { Value::Bytes(path) => { OwnedSegment::Field(String::from_utf8_lossy(&path).into()) } + #[allow(clippy::cast_possible_truncation)] //TODO evaluate removal options Value::Integer(index) => OwnedSegment::Index(index as isize), value => { return Err(format!( diff --git a/src/stdlib/slice.rs b/src/stdlib/slice.rs index 5b66f027f..6e7b93e39 100644 --- a/src/stdlib/slice.rs +++ b/src/stdlib/slice.rs @@ -4,6 +4,7 @@ use crate::compiler::prelude::*; #[allow(clippy::cast_possible_wrap)] #[allow(clippy::cast_sign_loss)] +#[allow(clippy::cast_possible_truncation)] //TODO evaluate removal options fn slice(start: i64, end: Option, value: Value) -> Resolved { let range = |len: i64| -> ExpressionResult> { let start = match start { diff --git a/src/stdlib/to_int.rs b/src/stdlib/to_int.rs index 4a6c4e804..084b6aec9 100644 --- a/src/stdlib/to_int.rs +++ b/src/stdlib/to_int.rs @@ -6,6 +6,7 @@ fn to_int(value: Value) -> Resolved { match value { Integer(_) => Ok(value), + #[allow(clippy::cast_possible_truncation)] //TODO evaluate removal options Float(v) => Ok(Integer(v.into_inner() as i64)), Boolean(v) => Ok(Integer(i64::from(v))), Null => Ok(0.into()), diff --git a/src/stdlib/uuid_v7.rs b/src/stdlib/uuid_v7.rs index 4f51c9ff8..6c0431a1b 100644 --- a/src/stdlib/uuid_v7.rs +++ b/src/stdlib/uuid_v7.rs @@ -13,6 +13,7 @@ fn uuid_v7(timestamp: Option) -> Resolved { let seconds = utc_timestamp.timestamp() as u64; let nanoseconds = match utc_timestamp.timestamp_nanos_opt() { + #[allow(clippy::cast_possible_truncation)] //TODO evaluate removal options Some(nanos) => nanos as u32, None => return Err(ValueError::OutOfRange(Kind::timestamp()).into()), }; From c166723d26c920f6a2deb89e446923fca3117352 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 17:03:18 -0500 Subject: [PATCH 4/9] cargo fmt --- src/stdlib/encode_gzip.rs | 3 ++- src/stdlib/encode_zlib.rs | 3 ++- src/stdlib/find.rs | 3 ++- src/stdlib/format_number.rs | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/stdlib/encode_gzip.rs b/src/stdlib/encode_gzip.rs index 9a1ecc1d4..3a8157b2b 100644 --- a/src/stdlib/encode_gzip.rs +++ b/src/stdlib/encode_gzip.rs @@ -11,7 +11,8 @@ fn encode_gzip(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); diff --git a/src/stdlib/encode_zlib.rs b/src/stdlib/encode_zlib.rs index 31558c6ee..b57ded8ae 100644 --- a/src/stdlib/encode_zlib.rs +++ b/src/stdlib/encode_zlib.rs @@ -11,7 +11,8 @@ fn encode_zlib(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); diff --git a/src/stdlib/find.rs b/src/stdlib/find.rs index fe657a1d3..1254e75b6 100644 --- a/src/stdlib/find.rs +++ b/src/stdlib/find.rs @@ -2,7 +2,8 @@ use crate::compiler::prelude::*; #[allow(clippy::cast_possible_wrap)] fn find(value: Value, pattern: Value, from: Option) -> Resolved { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let from = match from { Some(value) => value.try_integer()?, None => 0, diff --git a/src/stdlib/format_number.rs b/src/stdlib/format_number.rs index cc11f3202..9188a210a 100644 --- a/src/stdlib/format_number.rs +++ b/src/stdlib/format_number.rs @@ -41,7 +41,8 @@ fn format_number( match scale { Some(0) => parts.truncate(1), Some(i) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let i = i as usize; if parts.len() == 1 { From 866d146ceb4577aaa2effa9e1990833dbe1b2ed3 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 17:07:07 -0500 Subject: [PATCH 5/9] removed all breaking changes, replaced with allows --- src/stdlib/format_number.rs | 3 +-- src/stdlib/parse_etld.rs | 3 ++- src/stdlib/parse_int.rs | 3 ++- src/stdlib/random_bytes.rs | 9 ++++----- src/stdlib/replace.rs | 15 ++++++--------- src/stdlib/split.rs | 3 ++- src/stdlib/truncate.rs | 7 ++----- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/stdlib/format_number.rs b/src/stdlib/format_number.rs index 9188a210a..cc11f3202 100644 --- a/src/stdlib/format_number.rs +++ b/src/stdlib/format_number.rs @@ -41,8 +41,7 @@ fn format_number( match scale { Some(0) => parts.truncate(1), Some(i) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] - // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options let i = i as usize; if parts.len() == 1 { diff --git a/src/stdlib/parse_etld.rs b/src/stdlib/parse_etld.rs index edb5644c0..dc267ad8c 100644 --- a/src/stdlib/parse_etld.rs +++ b/src/stdlib/parse_etld.rs @@ -137,7 +137,8 @@ impl FunctionExpression for ParseEtldFn { let plus_parts = match self.plus_parts.resolve(ctx)?.try_integer()? { x if x < 0 => 0, - x => usize::try_from(x).map_err(|e| e.to_string())?, + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + x => x as usize, }; let suffix_result = if let Some(list) = &self.psl { diff --git a/src/stdlib/parse_int.rs b/src/stdlib/parse_int.rs index ba434b2a4..77912fe00 100644 --- a/src/stdlib/parse_int.rs +++ b/src/stdlib/parse_int.rs @@ -12,7 +12,8 @@ fn parse_int(value: Value, base: Option) -> Resolved { ) .into()); } - (u32::try_from(base).map_err(|e| e.to_string())?, 0) + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + (base as u32, 0) } None => match string.chars().next() { Some('0') => match string.chars().nth(1) { diff --git a/src/stdlib/random_bytes.rs b/src/stdlib/random_bytes.rs index ab45c0243..44b4cb12c 100644 --- a/src/stdlib/random_bytes.rs +++ b/src/stdlib/random_bytes.rs @@ -60,17 +60,16 @@ impl Function for RandomBytes { } } -fn get_length(value: Value) -> Result { - let length = value - .try_integer() - .map_err(|_| "Couldn't convert value to integer")?; +fn get_length(value: Value) -> std::result::Result { + let length = value.try_integer().expect("length must be an integer"); if length < 0 { return Err(LENGTH_TOO_SMALL_ERR); } if length > MAX_LENGTH { return Err(LENGTH_TOO_LARGE_ERR); } - usize::try_from(length).map_err(|_| "i64 to usize conversion failed") + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + Ok(length as usize) } #[derive(Debug, Clone)] diff --git a/src/stdlib/replace.rs b/src/stdlib/replace.rs index 0a79f8b6f..ae369768d 100644 --- a/src/stdlib/replace.rs +++ b/src/stdlib/replace.rs @@ -1,5 +1,6 @@ use crate::compiler::prelude::*; +#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options fn replace(value: Value, with_value: Value, count: Value, pattern: Value) -> Resolved { let value = value.try_bytes_utf8_lossy()?; let with = with_value.try_bytes_utf8_lossy()?; @@ -8,10 +9,7 @@ fn replace(value: Value, with_value: Value, count: Value, pattern: Value) -> Res Value::Bytes(bytes) => { let pattern = String::from_utf8_lossy(&bytes); let replaced = match count { - i if i > 0 => { - let i = usize::try_from(i).map_err(|e| e.to_string())?; - value.replacen(pattern.as_ref(), &with, i) - } + i if i > 0 => value.replacen(pattern.as_ref(), &with, i as usize), i if i < 0 => value.replace(pattern.as_ref(), &with), _ => value.into_owned(), }; @@ -20,11 +18,10 @@ fn replace(value: Value, with_value: Value, count: Value, pattern: Value) -> Res } Value::Regex(regex) => { let replaced = match count { - i if i > 0 => { - let i = usize::try_from(i).map_err(|e| e.to_string())?; - Bytes::copy_from_slice(regex.replacen(&value, i, with.as_ref()).as_bytes()) - .into() - } + i if i > 0 => Bytes::copy_from_slice( + regex.replacen(&value, i as usize, with.as_ref()).as_bytes(), + ) + .into(), i if i < 0 => { Bytes::copy_from_slice(regex.replace_all(&value, with.as_ref()).as_bytes()) .into() diff --git a/src/stdlib/split.rs b/src/stdlib/split.rs index b10f86671..451dc5cc8 100644 --- a/src/stdlib/split.rs +++ b/src/stdlib/split.rs @@ -4,7 +4,8 @@ fn split(value: Value, limit: Value, pattern: Value) -> Resolved { let string = value.try_bytes_utf8_lossy()?; let limit = match limit.try_integer()? { x if x < 0 => 0, - x => usize::try_from(x).map_err(|e| e.to_string())?, + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + x => x as usize, }; match pattern { Value::Regex(pattern) => Ok(pattern diff --git a/src/stdlib/truncate.rs b/src/stdlib/truncate.rs index d14189cc9..ad98931ad 100644 --- a/src/stdlib/truncate.rs +++ b/src/stdlib/truncate.rs @@ -3,11 +3,8 @@ use crate::compiler::prelude::*; fn truncate(value: Value, limit: Value, suffix: Value) -> Resolved { let mut value = value.try_bytes_utf8_lossy()?.into_owned(); let limit = limit.try_integer()?; - let limit = if limit < 0 { - 0 - } else { - usize::try_from(limit).map_err(|e| e.to_string())? - }; + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + let limit = if limit < 0 { 0 } else { limit as usize }; let suffix = suffix.try_bytes_utf8_lossy()?.to_string(); let pos = if let Some((pos, chr)) = value.char_indices().take(limit).last() { // char_indices gives us the starting position of the character at limit, From c4261c4db4ba8478f1806d633ca8ab76af1bca95 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 17:07:11 -0500 Subject: [PATCH 6/9] cargo fmt --- src/stdlib/format_number.rs | 3 ++- src/stdlib/parse_etld.rs | 3 ++- src/stdlib/parse_int.rs | 3 ++- src/stdlib/random_bytes.rs | 3 ++- src/stdlib/replace.rs | 2 +- src/stdlib/split.rs | 3 ++- src/stdlib/truncate.rs | 3 ++- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/stdlib/format_number.rs b/src/stdlib/format_number.rs index cc11f3202..9188a210a 100644 --- a/src/stdlib/format_number.rs +++ b/src/stdlib/format_number.rs @@ -41,7 +41,8 @@ fn format_number( match scale { Some(0) => parts.truncate(1), Some(i) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let i = i as usize; if parts.len() == 1 { diff --git a/src/stdlib/parse_etld.rs b/src/stdlib/parse_etld.rs index dc267ad8c..0b5cff687 100644 --- a/src/stdlib/parse_etld.rs +++ b/src/stdlib/parse_etld.rs @@ -137,7 +137,8 @@ impl FunctionExpression for ParseEtldFn { let plus_parts = match self.plus_parts.resolve(ctx)?.try_integer()? { x if x < 0 => 0, - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options x => x as usize, }; diff --git a/src/stdlib/parse_int.rs b/src/stdlib/parse_int.rs index 77912fe00..f4f041dcd 100644 --- a/src/stdlib/parse_int.rs +++ b/src/stdlib/parse_int.rs @@ -12,7 +12,8 @@ fn parse_int(value: Value, base: Option) -> Resolved { ) .into()); } - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options (base as u32, 0) } None => match string.chars().next() { diff --git a/src/stdlib/random_bytes.rs b/src/stdlib/random_bytes.rs index 44b4cb12c..844f051a0 100644 --- a/src/stdlib/random_bytes.rs +++ b/src/stdlib/random_bytes.rs @@ -68,7 +68,8 @@ fn get_length(value: Value) -> std::result::Result { if length > MAX_LENGTH { return Err(LENGTH_TOO_LARGE_ERR); } - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options Ok(length as usize) } diff --git a/src/stdlib/replace.rs b/src/stdlib/replace.rs index ae369768d..c04d06c28 100644 --- a/src/stdlib/replace.rs +++ b/src/stdlib/replace.rs @@ -21,7 +21,7 @@ fn replace(value: Value, with_value: Value, count: Value, pattern: Value) -> Res i if i > 0 => Bytes::copy_from_slice( regex.replacen(&value, i as usize, with.as_ref()).as_bytes(), ) - .into(), + .into(), i if i < 0 => { Bytes::copy_from_slice(regex.replace_all(&value, with.as_ref()).as_bytes()) .into() diff --git a/src/stdlib/split.rs b/src/stdlib/split.rs index 451dc5cc8..41ce090aa 100644 --- a/src/stdlib/split.rs +++ b/src/stdlib/split.rs @@ -4,7 +4,8 @@ fn split(value: Value, limit: Value, pattern: Value) -> Resolved { let string = value.try_bytes_utf8_lossy()?; let limit = match limit.try_integer()? { x if x < 0 => 0, - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options x => x as usize, }; match pattern { diff --git a/src/stdlib/truncate.rs b/src/stdlib/truncate.rs index ad98931ad..9faf4c5ac 100644 --- a/src/stdlib/truncate.rs +++ b/src/stdlib/truncate.rs @@ -3,7 +3,8 @@ use crate::compiler::prelude::*; fn truncate(value: Value, limit: Value, suffix: Value) -> Resolved { let mut value = value.try_bytes_utf8_lossy()?.into_owned(); let limit = limit.try_integer()?; - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let limit = if limit < 0 { 0 } else { limit as usize }; let suffix = suffix.try_bytes_utf8_lossy()?.to_string(); let pos = if let Some((pos, chr)) = value.char_indices().take(limit).last() { From 4ae63e410e828dd1715184feb28d3b22e96cdff8 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 17:10:28 -0500 Subject: [PATCH 7/9] a few more --- src/stdlib/encode_gzip.rs | 3 +-- src/stdlib/encode_zlib.rs | 3 +-- src/stdlib/format_number.rs | 3 +-- src/stdlib/parse_etld.rs | 3 +-- src/stdlib/parse_int.rs | 3 +-- src/stdlib/replace_with.rs | 3 ++- src/stdlib/truncate.rs | 3 +-- 7 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/stdlib/encode_gzip.rs b/src/stdlib/encode_gzip.rs index 3a8157b2b..9a1ecc1d4 100644 --- a/src/stdlib/encode_gzip.rs +++ b/src/stdlib/encode_gzip.rs @@ -11,8 +11,7 @@ fn encode_gzip(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] - // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); diff --git a/src/stdlib/encode_zlib.rs b/src/stdlib/encode_zlib.rs index b57ded8ae..31558c6ee 100644 --- a/src/stdlib/encode_zlib.rs +++ b/src/stdlib/encode_zlib.rs @@ -11,8 +11,7 @@ fn encode_zlib(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] - // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); diff --git a/src/stdlib/format_number.rs b/src/stdlib/format_number.rs index 9188a210a..cc11f3202 100644 --- a/src/stdlib/format_number.rs +++ b/src/stdlib/format_number.rs @@ -41,8 +41,7 @@ fn format_number( match scale { Some(0) => parts.truncate(1), Some(i) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] - // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options let i = i as usize; if parts.len() == 1 { diff --git a/src/stdlib/parse_etld.rs b/src/stdlib/parse_etld.rs index 0b5cff687..dc267ad8c 100644 --- a/src/stdlib/parse_etld.rs +++ b/src/stdlib/parse_etld.rs @@ -137,8 +137,7 @@ impl FunctionExpression for ParseEtldFn { let plus_parts = match self.plus_parts.resolve(ctx)?.try_integer()? { x if x < 0 => 0, - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] - // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options x => x as usize, }; diff --git a/src/stdlib/parse_int.rs b/src/stdlib/parse_int.rs index f4f041dcd..77912fe00 100644 --- a/src/stdlib/parse_int.rs +++ b/src/stdlib/parse_int.rs @@ -12,8 +12,7 @@ fn parse_int(value: Value, base: Option) -> Resolved { ) .into()); } - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] - // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options (base as u32, 0) } None => match string.chars().next() { diff --git a/src/stdlib/replace_with.rs b/src/stdlib/replace_with.rs index 4eea32c73..951782086 100644 --- a/src/stdlib/replace_with.rs +++ b/src/stdlib/replace_with.rs @@ -16,7 +16,8 @@ where { let haystack = value.try_bytes_utf8_lossy()?; let count = match count.try_integer()? { - i if i > 0 => usize::try_from(i).map_err(|e| e.to_string())?, + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + i if i > 0 => i as usize, i if i < 0 => 0, // this is when i == 0 _ => return Ok(value), diff --git a/src/stdlib/truncate.rs b/src/stdlib/truncate.rs index 9faf4c5ac..ad98931ad 100644 --- a/src/stdlib/truncate.rs +++ b/src/stdlib/truncate.rs @@ -3,8 +3,7 @@ use crate::compiler::prelude::*; fn truncate(value: Value, limit: Value, suffix: Value) -> Resolved { let mut value = value.try_bytes_utf8_lossy()?.into_owned(); let limit = limit.try_integer()?; - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] - // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options let limit = if limit < 0 { 0 } else { limit as usize }; let suffix = suffix.try_bytes_utf8_lossy()?.to_string(); let pos = if let Some((pos, chr)) = value.char_indices().take(limit).last() { From a14fe66e67aa4a37703c12a8133a577c7de8da3b Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 17:10:33 -0500 Subject: [PATCH 8/9] cargo fmt --- src/stdlib/encode_gzip.rs | 3 ++- src/stdlib/encode_zlib.rs | 3 ++- src/stdlib/format_number.rs | 3 ++- src/stdlib/parse_etld.rs | 3 ++- src/stdlib/parse_int.rs | 3 ++- src/stdlib/replace_with.rs | 3 ++- src/stdlib/truncate.rs | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/stdlib/encode_gzip.rs b/src/stdlib/encode_gzip.rs index 9a1ecc1d4..3a8157b2b 100644 --- a/src/stdlib/encode_gzip.rs +++ b/src/stdlib/encode_gzip.rs @@ -11,7 +11,8 @@ fn encode_gzip(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); diff --git a/src/stdlib/encode_zlib.rs b/src/stdlib/encode_zlib.rs index 31558c6ee..b57ded8ae 100644 --- a/src/stdlib/encode_zlib.rs +++ b/src/stdlib/encode_zlib.rs @@ -11,7 +11,8 @@ fn encode_zlib(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); diff --git a/src/stdlib/format_number.rs b/src/stdlib/format_number.rs index cc11f3202..9188a210a 100644 --- a/src/stdlib/format_number.rs +++ b/src/stdlib/format_number.rs @@ -41,7 +41,8 @@ fn format_number( match scale { Some(0) => parts.truncate(1), Some(i) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let i = i as usize; if parts.len() == 1 { diff --git a/src/stdlib/parse_etld.rs b/src/stdlib/parse_etld.rs index dc267ad8c..0b5cff687 100644 --- a/src/stdlib/parse_etld.rs +++ b/src/stdlib/parse_etld.rs @@ -137,7 +137,8 @@ impl FunctionExpression for ParseEtldFn { let plus_parts = match self.plus_parts.resolve(ctx)?.try_integer()? { x if x < 0 => 0, - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options x => x as usize, }; diff --git a/src/stdlib/parse_int.rs b/src/stdlib/parse_int.rs index 77912fe00..f4f041dcd 100644 --- a/src/stdlib/parse_int.rs +++ b/src/stdlib/parse_int.rs @@ -12,7 +12,8 @@ fn parse_int(value: Value, base: Option) -> Resolved { ) .into()); } - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options (base as u32, 0) } None => match string.chars().next() { diff --git a/src/stdlib/replace_with.rs b/src/stdlib/replace_with.rs index 951782086..ffbaf3468 100644 --- a/src/stdlib/replace_with.rs +++ b/src/stdlib/replace_with.rs @@ -16,7 +16,8 @@ where { let haystack = value.try_bytes_utf8_lossy()?; let count = match count.try_integer()? { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options i if i > 0 => i as usize, i if i < 0 => 0, // this is when i == 0 diff --git a/src/stdlib/truncate.rs b/src/stdlib/truncate.rs index ad98931ad..9faf4c5ac 100644 --- a/src/stdlib/truncate.rs +++ b/src/stdlib/truncate.rs @@ -3,7 +3,8 @@ use crate::compiler::prelude::*; fn truncate(value: Value, limit: Value, suffix: Value) -> Resolved { let mut value = value.try_bytes_utf8_lossy()?.into_owned(); let limit = limit.try_integer()?; - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] + // TODO consider removal options let limit = if limit < 0 { 0 } else { limit as usize }; let suffix = suffix.try_bytes_utf8_lossy()?.to_string(); let pos = if let Some((pos, chr)) = value.char_indices().take(limit).last() { From 4a1883bcba5796d594549fd3da5dc13f031392b1 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Tue, 28 Jan 2025 19:45:07 -0500 Subject: [PATCH 9/9] move comment above #allow, cargo fmt moved it... --- src/stdlib/encode_gzip.rs | 2 +- src/stdlib/encode_zlib.rs | 2 +- src/stdlib/find.rs | 2 +- src/stdlib/format_number.rs | 2 +- src/stdlib/parse_etld.rs | 2 +- src/stdlib/parse_int.rs | 2 +- src/stdlib/random_bytes.rs | 2 +- src/stdlib/replace_with.rs | 2 +- src/stdlib/split.rs | 2 +- src/stdlib/truncate.rs | 2 +- src/stdlib/uuid_v7.rs | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/stdlib/encode_gzip.rs b/src/stdlib/encode_gzip.rs index 3a8157b2b..9238a8b77 100644 --- a/src/stdlib/encode_gzip.rs +++ b/src/stdlib/encode_gzip.rs @@ -11,8 +11,8 @@ fn encode_gzip(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); diff --git a/src/stdlib/encode_zlib.rs b/src/stdlib/encode_zlib.rs index b57ded8ae..66b32d629 100644 --- a/src/stdlib/encode_zlib.rs +++ b/src/stdlib/encode_zlib.rs @@ -11,8 +11,8 @@ fn encode_zlib(value: Value, compression_level: Option) -> Resolved { let compression_level = match compression_level { None => flate2::Compression::default(), Some(value) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] let level = value.try_integer()? as u32; if level > MAX_COMPRESSION_LEVEL { return Err(format!("compression level must be <= {MAX_COMPRESSION_LEVEL}").into()); diff --git a/src/stdlib/find.rs b/src/stdlib/find.rs index 1254e75b6..25a9c3965 100644 --- a/src/stdlib/find.rs +++ b/src/stdlib/find.rs @@ -2,8 +2,8 @@ use crate::compiler::prelude::*; #[allow(clippy::cast_possible_wrap)] fn find(value: Value, pattern: Value, from: Option) -> Resolved { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] let from = match from { Some(value) => value.try_integer()?, None => 0, diff --git a/src/stdlib/format_number.rs b/src/stdlib/format_number.rs index 9188a210a..3bb6de15a 100644 --- a/src/stdlib/format_number.rs +++ b/src/stdlib/format_number.rs @@ -41,8 +41,8 @@ fn format_number( match scale { Some(0) => parts.truncate(1), Some(i) => { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] let i = i as usize; if parts.len() == 1 { diff --git a/src/stdlib/parse_etld.rs b/src/stdlib/parse_etld.rs index 0b5cff687..fcadd90c2 100644 --- a/src/stdlib/parse_etld.rs +++ b/src/stdlib/parse_etld.rs @@ -137,8 +137,8 @@ impl FunctionExpression for ParseEtldFn { let plus_parts = match self.plus_parts.resolve(ctx)?.try_integer()? { x if x < 0 => 0, - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] x => x as usize, }; diff --git a/src/stdlib/parse_int.rs b/src/stdlib/parse_int.rs index f4f041dcd..e19ed47bb 100644 --- a/src/stdlib/parse_int.rs +++ b/src/stdlib/parse_int.rs @@ -12,8 +12,8 @@ fn parse_int(value: Value, base: Option) -> Resolved { ) .into()); } - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] (base as u32, 0) } None => match string.chars().next() { diff --git a/src/stdlib/random_bytes.rs b/src/stdlib/random_bytes.rs index 844f051a0..c3d20b120 100644 --- a/src/stdlib/random_bytes.rs +++ b/src/stdlib/random_bytes.rs @@ -68,8 +68,8 @@ fn get_length(value: Value) -> std::result::Result { if length > MAX_LENGTH { return Err(LENGTH_TOO_LARGE_ERR); } - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] Ok(length as usize) } diff --git a/src/stdlib/replace_with.rs b/src/stdlib/replace_with.rs index ffbaf3468..d30870509 100644 --- a/src/stdlib/replace_with.rs +++ b/src/stdlib/replace_with.rs @@ -16,8 +16,8 @@ where { let haystack = value.try_bytes_utf8_lossy()?; let count = match count.try_integer()? { - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] i if i > 0 => i as usize, i if i < 0 => 0, // this is when i == 0 diff --git a/src/stdlib/split.rs b/src/stdlib/split.rs index 41ce090aa..a318eacd9 100644 --- a/src/stdlib/split.rs +++ b/src/stdlib/split.rs @@ -4,8 +4,8 @@ fn split(value: Value, limit: Value, pattern: Value) -> Resolved { let string = value.try_bytes_utf8_lossy()?; let limit = match limit.try_integer()? { x if x < 0 => 0, - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] x => x as usize, }; match pattern { diff --git a/src/stdlib/truncate.rs b/src/stdlib/truncate.rs index 9faf4c5ac..c13b40e27 100644 --- a/src/stdlib/truncate.rs +++ b/src/stdlib/truncate.rs @@ -3,8 +3,8 @@ use crate::compiler::prelude::*; fn truncate(value: Value, limit: Value, suffix: Value) -> Resolved { let mut value = value.try_bytes_utf8_lossy()?.into_owned(); let limit = limit.try_integer()?; - #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] // TODO consider removal options + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] let limit = if limit < 0 { 0 } else { limit as usize }; let suffix = suffix.try_bytes_utf8_lossy()?.to_string(); let pos = if let Some((pos, chr)) = value.char_indices().take(limit).last() { diff --git a/src/stdlib/uuid_v7.rs b/src/stdlib/uuid_v7.rs index 6c0431a1b..f1d7451b3 100644 --- a/src/stdlib/uuid_v7.rs +++ b/src/stdlib/uuid_v7.rs @@ -3,7 +3,7 @@ use bytes::Bytes; use chrono::{DateTime, Utc}; use uuid::{timestamp::Timestamp, NoContext}; -#[allow(clippy::cast_sign_loss)] +#[allow(clippy::cast_sign_loss)] // TODO consider removal options fn uuid_v7(timestamp: Option) -> Resolved { let utc_timestamp: DateTime = if let Some(timestamp) = timestamp { timestamp.try_timestamp()?