Skip to content

Commit db5197b

Browse files
authored
chore: Replace matches! on fieldless enums with == (#20525)
## Which issue does this PR close? N/A ## Rationale for this change When comparing a value with a field-less enum that implements `PartialEq`, `==` is simpler and more readable than `matches!`. ## What changes are included in this PR? ## Are these changes tested? Yes. ## Are there any user-facing changes? No.
1 parent 932418b commit db5197b

34 files changed

Lines changed: 60 additions & 64 deletions

File tree

datafusion/common/src/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ mod tests {
12651265
col_stats.min_value,
12661266
Precision::Inexact(ScalarValue::Int32(Some(-10)))
12671267
);
1268-
assert!(matches!(col_stats.sum_value, Precision::Absent));
1268+
assert_eq!(col_stats.sum_value, Precision::Absent);
12691269
}
12701270

12711271
#[test]

datafusion/common/src/types/native.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl NativeType {
499499

500500
#[inline]
501501
pub fn is_date(&self) -> bool {
502-
matches!(self, NativeType::Date)
502+
*self == NativeType::Date
503503
}
504504

505505
#[inline]
@@ -524,7 +524,7 @@ impl NativeType {
524524

525525
#[inline]
526526
pub fn is_null(&self) -> bool {
527-
matches!(self, NativeType::Null)
527+
*self == NativeType::Null
528528
}
529529

530530
#[inline]

datafusion/core/src/physical_planner.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ impl DefaultPhysicalPlanner {
13951395

13961396
// TODO: Allow PWMJ to deal with residual equijoin conditions
13971397
let join: Arc<dyn ExecutionPlan> = if join_on.is_empty() {
1398-
if join_filter.is_none() && matches!(join_type, JoinType::Inner) {
1398+
if join_filter.is_none() && *join_type == JoinType::Inner {
13991399
// cross join if there is no join conditions and no join filter set
14001400
Arc::new(CrossJoinExec::new(physical_left, physical_right))
14011401
} else if num_range_filters == 1
@@ -1470,9 +1470,7 @@ impl DefaultPhysicalPlanner {
14701470

14711471
let left_side = side_of(lhs_logical)?;
14721472
let right_side = side_of(rhs_logical)?;
1473-
if matches!(left_side, Side::Both)
1474-
|| matches!(right_side, Side::Both)
1475-
{
1473+
if left_side == Side::Both || right_side == Side::Both {
14761474
return Ok(Arc::new(NestedLoopJoinExec::try_new(
14771475
physical_left,
14781476
physical_right,
@@ -3553,12 +3551,12 @@ mod tests {
35533551
assert!(
35543552
stringified_plans
35553553
.iter()
3556-
.any(|p| matches!(p.plan_type, PlanType::FinalLogicalPlan))
3554+
.any(|p| p.plan_type == PlanType::FinalLogicalPlan)
35573555
);
35583556
assert!(
35593557
stringified_plans
35603558
.iter()
3561-
.any(|p| matches!(p.plan_type, PlanType::InitialPhysicalPlan))
3559+
.any(|p| p.plan_type == PlanType::InitialPhysicalPlan)
35623560
);
35633561
assert!(
35643562
stringified_plans.iter().any(|p| matches!(
@@ -3569,7 +3567,7 @@ mod tests {
35693567
assert!(
35703568
stringified_plans
35713569
.iter()
3572-
.any(|p| matches!(p.plan_type, PlanType::FinalPhysicalPlan))
3570+
.any(|p| p.plan_type == PlanType::FinalPhysicalPlan)
35733571
);
35743572
} else {
35753573
panic!(

datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ async fn verify_ordered_aggregate(frame: &DataFrame, expected_sort: bool) {
554554
InputOrderMode::PartiallySorted(_) | InputOrderMode::Sorted
555555
));
556556
} else {
557-
assert!(matches!(exec.input_order_mode(), InputOrderMode::Linear));
557+
assert_eq!(*exec.input_order_mode(), InputOrderMode::Linear);
558558
}
559559
}
560560
Ok(TreeNodeRecursion::Continue)

datafusion/core/tests/fuzz_cases/window_fuzz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ async fn run_window_test(
589589
orderby_columns: Vec<&str>,
590590
search_mode: InputOrderMode,
591591
) -> Result<()> {
592-
let is_linear = !matches!(search_mode, Sorted);
592+
let is_linear = search_mode != Sorted;
593593
let mut rng = StdRng::seed_from_u64(random_seed);
594594
let schema = input1[0].schema();
595595
let session_config = SessionConfig::new().with_batch_size(50);

datafusion/expr-common/src/signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ impl Signature {
14161416
Arity::Variable => {
14171417
// For UserDefined signatures, allow parameter names
14181418
// The function implementer is responsible for validating the names match the actual arguments
1419-
if !matches!(self.type_signature, TypeSignature::UserDefined) {
1419+
if self.type_signature != TypeSignature::UserDefined {
14201420
return plan_err!(
14211421
"Cannot specify parameter names for variable arity signature: {:?}",
14221422
self.type_signature

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl From<&DataType> for TypeCategory {
526526
return TypeCategory::Numeric;
527527
}
528528

529-
if matches!(data_type, DataType::Boolean) {
529+
if *data_type == DataType::Boolean {
530530
return TypeCategory::Boolean;
531531
}
532532

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ impl LogicalPlan {
19651965
.unwrap_or_else(|| "".to_string());
19661966
let join_type = if filter.is_none()
19671967
&& keys.is_empty()
1968-
&& matches!(join_type, JoinType::Inner)
1968+
&& *join_type == JoinType::Inner
19691969
{
19701970
"Cross".to_string()
19711971
} else {

datafusion/functions-aggregate/src/regr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl AggregateUDFImpl for Regr {
455455
}
456456

457457
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
458-
if matches!(self.regr_type, RegrType::Count) {
458+
if self.regr_type == RegrType::Count {
459459
Ok(DataType::UInt64)
460460
} else {
461461
Ok(DataType::Float64)

datafusion/functions-window/src/nth_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl WindowUDFImpl for NthValue {
269269
kind: self.kind,
270270
};
271271

272-
if !matches!(self.kind, NthValueKind::Nth) {
272+
if self.kind != NthValueKind::Nth {
273273
return Ok(Box::new(NthValueEvaluator {
274274
state,
275275
ignore_nulls: partition_evaluator_args.ignore_nulls(),

0 commit comments

Comments
 (0)