Skip to content

Commit 958a6de

Browse files
authored
chore: Enforce 'clippy::needless_pass_by_value' to datafusion-expr-common (apache#18775)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes apache#18760 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> Cargo clippy and tests still pass ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> No <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent 0304cda commit 958a6de

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

datafusion/expr-common/src/interval_arithmetic.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,12 @@ impl Interval {
858858
) {
859859
(true, true, false) => mul_helper_multi_zero_inclusive(&dt, self, rhs),
860860
(true, false, false) => {
861-
mul_helper_single_zero_inclusive(&dt, self, rhs, zero)
861+
mul_helper_single_zero_inclusive(&dt, self, rhs, &zero)
862862
}
863863
(false, true, false) => {
864-
mul_helper_single_zero_inclusive(&dt, rhs, self, zero)
864+
mul_helper_single_zero_inclusive(&dt, rhs, self, &zero)
865865
}
866-
_ => mul_helper_zero_exclusive(&dt, self, rhs, zero),
866+
_ => mul_helper_zero_exclusive(&dt, self, rhs, &zero),
867867
};
868868
Ok(result)
869869
}
@@ -1462,10 +1462,10 @@ fn mul_helper_single_zero_inclusive(
14621462
dt: &DataType,
14631463
lhs: &Interval,
14641464
rhs: &Interval,
1465-
zero: ScalarValue,
1465+
zero: &ScalarValue,
14661466
) -> Interval {
14671467
// With the following interval bounds, there is no possibility to create an invalid interval.
1468-
if rhs.upper <= zero && !rhs.upper.is_null() {
1468+
if rhs.upper <= *zero && !rhs.upper.is_null() {
14691469
// <-------=====0=====------->
14701470
// <--======----0------------>
14711471
let lower = mul_bounds::<false>(dt, &lhs.upper, &rhs.lower);
@@ -1514,11 +1514,11 @@ fn mul_helper_zero_exclusive(
15141514
dt: &DataType,
15151515
lhs: &Interval,
15161516
rhs: &Interval,
1517-
zero: ScalarValue,
1517+
zero: &ScalarValue,
15181518
) -> Interval {
15191519
let (lower, upper) = match (
1520-
lhs.upper <= zero && !lhs.upper.is_null(),
1521-
rhs.upper <= zero && !rhs.upper.is_null(),
1520+
lhs.upper <= *zero && !lhs.upper.is_null(),
1521+
rhs.upper <= *zero && !rhs.upper.is_null(),
15221522
) {
15231523
// With the following interval bounds, there is no possibility to create an invalid interval.
15241524
(true, true) => (

datafusion/expr-common/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
// Make sure fast / cheap clones on Arc are explicit:
3232
// https://github.com/apache/datafusion/issues/11143
3333
#![deny(clippy::clone_on_ref_ptr)]
34+
// https://github.com/apache/datafusion/issues/18503
35+
#![deny(clippy::needless_pass_by_value)]
36+
#![cfg_attr(test, allow(clippy::needless_pass_by_value))]
3437

3538
pub mod accumulator;
3639
pub mod casts;

datafusion/expr-common/src/type_coercion/binary.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ fn string_temporal_coercion(
933933
match temporal {
934934
Date32 | Date64 => Some(temporal.clone()),
935935
Time32(_) | Time64(_) => {
936-
if is_time_with_valid_unit(temporal.to_owned()) {
936+
if is_time_with_valid_unit(temporal) {
937937
Some(temporal.to_owned())
938938
} else {
939939
None
@@ -1703,13 +1703,13 @@ pub fn regex_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Option<DataTy
17031703
/// Checks if the TimeUnit associated with a Time32 or Time64 type is consistent,
17041704
/// as Time32 can only be used to Second and Millisecond accuracy, while Time64
17051705
/// is exclusively used to Microsecond and Nanosecond accuracy
1706-
fn is_time_with_valid_unit(datatype: DataType) -> bool {
1706+
fn is_time_with_valid_unit(datatype: &DataType) -> bool {
17071707
matches!(
17081708
datatype,
1709-
DataType::Time32(TimeUnit::Second)
1710-
| DataType::Time32(TimeUnit::Millisecond)
1711-
| DataType::Time64(TimeUnit::Microsecond)
1712-
| DataType::Time64(TimeUnit::Nanosecond)
1709+
&DataType::Time32(TimeUnit::Second)
1710+
| &DataType::Time32(TimeUnit::Millisecond)
1711+
| &DataType::Time64(TimeUnit::Microsecond)
1712+
| &DataType::Time64(TimeUnit::Nanosecond)
17131713
)
17141714
}
17151715

0 commit comments

Comments
 (0)