diff --git a/datafusion/expr-common/src/interval_arithmetic.rs b/datafusion/expr-common/src/interval_arithmetic.rs index 9ea9d9275f84..d02927cc7cc4 100644 --- a/datafusion/expr-common/src/interval_arithmetic.rs +++ b/datafusion/expr-common/src/interval_arithmetic.rs @@ -847,12 +847,12 @@ impl Interval { ) { (true, true, false) => mul_helper_multi_zero_inclusive(&dt, self, rhs), (true, false, false) => { - mul_helper_single_zero_inclusive(&dt, self, rhs, zero) + mul_helper_single_zero_inclusive(&dt, self, rhs, &zero) } (false, true, false) => { - mul_helper_single_zero_inclusive(&dt, rhs, self, zero) + mul_helper_single_zero_inclusive(&dt, rhs, self, &zero) } - _ => mul_helper_zero_exclusive(&dt, self, rhs, zero), + _ => mul_helper_zero_exclusive(&dt, self, rhs, &zero), }; Ok(result) } @@ -1454,10 +1454,10 @@ fn mul_helper_single_zero_inclusive( dt: &DataType, lhs: &Interval, rhs: &Interval, - zero: ScalarValue, + zero: &ScalarValue, ) -> Interval { // With the following interval bounds, there is no possibility to create an invalid interval. - if rhs.upper <= zero && !rhs.upper.is_null() { + if rhs.upper <= *zero && !rhs.upper.is_null() { // <-------=====0=====-------> // <--======----0------------> let lower = mul_bounds::(dt, &lhs.upper, &rhs.lower); @@ -1506,11 +1506,11 @@ fn mul_helper_zero_exclusive( dt: &DataType, lhs: &Interval, rhs: &Interval, - zero: ScalarValue, + zero: &ScalarValue, ) -> Interval { let (lower, upper) = match ( - lhs.upper <= zero && !lhs.upper.is_null(), - rhs.upper <= zero && !rhs.upper.is_null(), + lhs.upper <= *zero && !lhs.upper.is_null(), + rhs.upper <= *zero && !rhs.upper.is_null(), ) { // With the following interval bounds, there is no possibility to create an invalid interval. (true, true) => ( diff --git a/datafusion/expr-common/src/lib.rs b/datafusion/expr-common/src/lib.rs index a4f6414a8c51..5323c3cb1835 100644 --- a/datafusion/expr-common/src/lib.rs +++ b/datafusion/expr-common/src/lib.rs @@ -31,6 +31,9 @@ // Make sure fast / cheap clones on Arc are explicit: // https://github.com/apache/datafusion/issues/11143 #![deny(clippy::clone_on_ref_ptr)] +// https://github.com/apache/datafusion/issues/18503 +#![deny(clippy::needless_pass_by_value)] +#![cfg_attr(test, allow(clippy::needless_pass_by_value))] pub mod accumulator; pub mod casts; diff --git a/datafusion/expr-common/src/type_coercion/binary.rs b/datafusion/expr-common/src/type_coercion/binary.rs index 44f1a42c5435..4aacc7533c64 100644 --- a/datafusion/expr-common/src/type_coercion/binary.rs +++ b/datafusion/expr-common/src/type_coercion/binary.rs @@ -933,7 +933,7 @@ fn string_temporal_coercion( match temporal { Date32 | Date64 => Some(temporal.clone()), Time32(_) | Time64(_) => { - if is_time_with_valid_unit(temporal.to_owned()) { + if is_time_with_valid_unit(temporal) { Some(temporal.to_owned()) } else { None @@ -1703,13 +1703,13 @@ pub fn regex_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option bool { +fn is_time_with_valid_unit(datatype: &DataType) -> bool { matches!( datatype, - DataType::Time32(TimeUnit::Second) - | DataType::Time32(TimeUnit::Millisecond) - | DataType::Time64(TimeUnit::Microsecond) - | DataType::Time64(TimeUnit::Nanosecond) + &DataType::Time32(TimeUnit::Second) + | &DataType::Time32(TimeUnit::Millisecond) + | &DataType::Time64(TimeUnit::Microsecond) + | &DataType::Time64(TimeUnit::Nanosecond) ) }