Skip to content

Commit

Permalink
chore: resolve redundant_closure_for_method_calls lint warnings (#226)
Browse files Browse the repository at this point in the history
# Rationale for this change

We have cargo clippy running in our CI in order to enforce code quality.
In order to increase our standards, we should enable the
clippy::pedantic lint group.

# What changes are included in this PR?

Resolved `redundant_closure_for_method_calls` lint warnings

# Are these changes tested?

Yes.

---------

Co-authored-by: Jay White <[email protected]>
  • Loading branch information
mehulmathur16 and JayWhite2357 authored Oct 7, 2024
1 parent a32364a commit 3cc7a75
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 103 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ range_plus_one = "deny"
cloned_instead_of_copied = "deny"
from_iter_instead_of_collect = "deny"
cast_lossless = "deny"
redundant_closure_for_method_calls = "deny"
inconsistent_struct_constructor = "deny"
default_trait_access = "deny"
43 changes: 25 additions & 18 deletions crates/proof-of-sql/src/base/commitment/naive_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Neg for NaiveCommitment {
type Output = NaiveCommitment;

fn neg(self) -> Self::Output {
Self(self.0.iter().map(|s| s.neg()).collect())
Self(self.0.iter().map(core::ops::Neg::neg).collect())
}
}

Expand Down Expand Up @@ -119,36 +119,40 @@ impl Commitment for NaiveCommitment {
let mut vectors: Vec<TestScalar> = vec![TestScalar::ZERO; offset];
let mut existing_scalars: Vec<TestScalar> = match cc {
CommittableColumn::Boolean(bool_vec) => {
bool_vec.iter().map(|b| b.into()).collect()
bool_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::TinyInt(tiny_int_vec) => {
tiny_int_vec.iter().map(|b| b.into()).collect()
tiny_int_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::SmallInt(small_int_vec) => {
small_int_vec.iter().map(|b| b.into()).collect()
CommittableColumn::SmallInt(small_int_vec) => small_int_vec
.iter()
.map(core::convert::Into::into)
.collect(),
CommittableColumn::Int(int_vec) => {
int_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::Int(int_vec) => int_vec.iter().map(|b| b.into()).collect(),
CommittableColumn::BigInt(big_int_vec) => {
big_int_vec.iter().map(|b| b.into()).collect()
big_int_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::Int128(int_128_vec) => {
int_128_vec.iter().map(|b| b.into()).collect()
int_128_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::Decimal75(_, _, u64_vec) => {
u64_vec.iter().map(|b| b.into()).collect()
u64_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::Scalar(scalar_vec) => {
scalar_vec.iter().map(|b| b.into()).collect()
scalar_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::VarChar(varchar_vec) => {
varchar_vec.iter().map(|b| b.into()).collect()
varchar_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::TimestampTZ(_, _, i64_vec) => {
i64_vec.iter().map(|b| b.into()).collect()
}
CommittableColumn::RangeCheckWord(u8_scalar_vec) => {
u8_scalar_vec.iter().map(|b| b.into()).collect()
i64_vec.iter().map(core::convert::Into::into).collect()
}
CommittableColumn::RangeCheckWord(u8_scalar_vec) => u8_scalar_vec
.iter()
.map(core::convert::Into::into)
.collect(),
};
vectors.append(&mut existing_scalars);
NaiveCommitment(vectors)
Expand All @@ -168,8 +172,10 @@ fn we_can_compute_commitments_from_commitable_columns() {
[4, 0, 0, 0],
[5, 0, 0, 0],
];
let column_a_scalars: Vec<TestScalar> = column_a.iter().map(|a| a.into()).collect();
let column_b_scalars: Vec<TestScalar> = column_b.iter().map(|b| b.into()).collect();
let column_a_scalars: Vec<TestScalar> =
column_a.iter().map(core::convert::Into::into).collect();
let column_b_scalars: Vec<TestScalar> =
column_b.iter().map(core::convert::Into::into).collect();
let commitable_column_a = CommittableColumn::BigInt(&column_a);
let commitable_column_b = CommittableColumn::VarChar(column_b);
let committable_columns: &[CommittableColumn] = &[commitable_column_a, commitable_column_b];
Expand All @@ -181,7 +187,8 @@ fn we_can_compute_commitments_from_commitable_columns() {
#[test]
fn we_can_compute_commitments_from_commitable_columns_with_offset() {
let column_a = [0i64, 1, 10, -5, 0, 10];
let column_a_scalars: Vec<TestScalar> = column_a.iter().map(|a| a.into()).collect();
let column_a_scalars: Vec<TestScalar> =
column_a.iter().map(core::convert::Into::into).collect();
let commitable_column_a = CommittableColumn::BigInt(&column_a[1..]);
let committable_columns: &[CommittableColumn] = &[commitable_column_a];
let commitments = NaiveCommitment::compute_commitments(committable_columns, 1, &());
Expand Down
137 changes: 106 additions & 31 deletions crates/proof-of-sql/src/base/commitment/naive_commitment_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ use alloc::vec::Vec;

#[test]
fn we_can_compare_columns_with_equal_length() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_b: Vec<TestScalar> = [1i64, 10, -5, 0, 11].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = [1i64, 10, -5, 0, 11]
.iter()
.map(core::convert::Into::into)
.collect();
let commitment_a = NaiveCommitment(column_a.clone());
let commitment_b = NaiveCommitment(column_b);
let commitment_c = NaiveCommitment(column_a);
Expand All @@ -21,10 +27,16 @@ fn we_can_compare_columns_with_equal_length() {
fn we_can_compare_columns_with_different_length() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 11, 0]
.iter()
.map(|bi| bi.into())
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = [1i64, 10, -5, 0, 11]
.iter()
.map(core::convert::Into::into)
.collect();
let column_c: Vec<TestScalar> = [1i64, 10, -5]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = [1i64, 10, -5, 0, 11].iter().map(|bi| bi.into()).collect();
let column_c: Vec<TestScalar> = [1i64, 10, -5].iter().map(|bi| bi.into()).collect();
let commitment_a = NaiveCommitment(column_a.clone());
let commitment_b = NaiveCommitment(column_b);
let commitment_c = NaiveCommitment(column_c);
Expand All @@ -38,7 +50,10 @@ fn we_can_compare_columns_with_different_length() {

#[test]
fn we_can_compare_columns_with_at_least_one_empty() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = Vec::new();
let commitment_a = NaiveCommitment(column_a);
let commitment_b = NaiveCommitment(column_b.clone());
Expand All @@ -53,9 +68,18 @@ fn we_can_compare_columns_with_at_least_one_empty() {

#[test]
fn we_can_add_naive_commitments() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_b: Vec<TestScalar> = [2i64, -10, -5, 5, 100].iter().map(|bi| bi.into()).collect();
let column_sum: Vec<TestScalar> = [3i64, 0, -10, 5, 110].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = [2i64, -10, -5, 5, 100]
.iter()
.map(core::convert::Into::into)
.collect();
let column_sum: Vec<TestScalar> = [3i64, 0, -10, 5, 110]
.iter()
.map(core::convert::Into::into)
.collect();

let commitment_a = NaiveCommitment(column_a);
let commitment_b = NaiveCommitment(column_b);
Expand All @@ -69,7 +93,10 @@ fn we_can_add_naive_commitments() {

#[test]
fn we_can_add_naive_commitments_with_one_empty() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = Vec::new();

let commitment_a = NaiveCommitment(column_a);
Expand Down Expand Up @@ -97,10 +124,18 @@ fn we_can_add_naive_commitments_with_both_empty() {

#[test]
fn we_can_subtract_naive_commitments() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_b: Vec<TestScalar> = [2i64, -10, -5, 5, 100].iter().map(|bi| bi.into()).collect();
let column_difference: Vec<TestScalar> =
[-1i64, 20, 0, -5, -90].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = [2i64, -10, -5, 5, 100]
.iter()
.map(core::convert::Into::into)
.collect();
let column_difference: Vec<TestScalar> = [-1i64, 20, 0, -5, -90]
.iter()
.map(core::convert::Into::into)
.collect();

let commitment_a = NaiveCommitment(column_a);
let commitment_b = NaiveCommitment(column_b);
Expand All @@ -112,9 +147,15 @@ fn we_can_subtract_naive_commitments() {

#[test]
fn we_can_subtract_naive_commitments_with_one_empty() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = Vec::new();
let column_b_minus_a = [-1i64, -10, 5, 0, -10].iter().map(|bi| bi.into()).collect();
let column_b_minus_a = [-1i64, -10, 5, 0, -10]
.iter()
.map(core::convert::Into::into)
.collect();

let commitment_a = NaiveCommitment(column_a.clone());
let commitment_b = NaiveCommitment(column_b);
Expand Down Expand Up @@ -146,9 +187,18 @@ fn we_can_subtract_naive_commitments_with_both_empty() {
#[allow(clippy::similar_names)]
#[test]
fn we_can_add_assign_naive_commitments() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_b: Vec<TestScalar> = [2i64, -10, -5, 5, 100].iter().map(|bi| bi.into()).collect();
let column_sum: Vec<TestScalar> = [3i64, 0, -10, 5, 110].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = [2i64, -10, -5, 5, 100]
.iter()
.map(core::convert::Into::into)
.collect();
let column_sum: Vec<TestScalar> = [3i64, 0, -10, 5, 110]
.iter()
.map(core::convert::Into::into)
.collect();

let commitment_a = NaiveCommitment(column_a.clone());
let commitment_b = NaiveCommitment(column_b.clone());
Expand All @@ -169,7 +219,10 @@ fn we_can_add_assign_naive_commitments() {
#[allow(clippy::similar_names)]
#[test]
fn we_can_add_assign_naive_commitments_with_one_empty() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = Vec::new();

let commitment_a = NaiveCommitment(column_a.clone());
Expand Down Expand Up @@ -206,10 +259,18 @@ fn we_can_add_assign_naive_commitments_with_both_empty() {

#[test]
fn we_can_sub_assign_naive_commitments() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_b: Vec<TestScalar> = [2i64, -10, -5, 5, 100].iter().map(|bi| bi.into()).collect();
let column_difference: Vec<TestScalar> =
[-1i64, 20, 0, -5, -90].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = [2i64, -10, -5, 5, 100]
.iter()
.map(core::convert::Into::into)
.collect();
let column_difference: Vec<TestScalar> = [-1i64, 20, 0, -5, -90]
.iter()
.map(core::convert::Into::into)
.collect();

let commitment_b = NaiveCommitment(column_b.clone());
let mut commitment_a_mutable = NaiveCommitment(column_a);
Expand All @@ -225,9 +286,15 @@ fn we_can_sub_assign_naive_commitments() {
#[allow(clippy::similar_names)]
#[test]
fn we_can_sub_assign_naive_commitments_with_one_empty() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_b: Vec<TestScalar> = Vec::new();
let column_b_minus_a = [-1i64, -10, 5, 0, -10].iter().map(|bi| bi.into()).collect();
let column_b_minus_a = [-1i64, -10, 5, 0, -10]
.iter()
.map(core::convert::Into::into)
.collect();

let commitment_a = NaiveCommitment(column_a.clone());
let commitment_b = NaiveCommitment(column_b.clone());
Expand Down Expand Up @@ -263,9 +330,14 @@ fn we_can_sub_assign_naive_commitments_with_both_empty() {

#[test]
fn we_can_negate_naive_commitments() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_negation: Vec<TestScalar> =
[-1i64, -10, 5, 0, -10].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_negation: Vec<TestScalar> = [-1i64, -10, 5, 0, -10]
.iter()
.map(core::convert::Into::into)
.collect();

let commitment_a = NaiveCommitment(column_a);
let commitment_negation = NaiveCommitment(column_negation);
Expand All @@ -291,13 +363,16 @@ fn we_can_negate_empty_naive_commitments() {

#[test]
fn we_can_do_scalar_multiplication() {
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10].iter().map(|bi| bi.into()).collect();
let column_a: Vec<TestScalar> = [1i64, 10, -5, 0, 10]
.iter()
.map(core::convert::Into::into)
.collect();
let column_empty: Vec<TestScalar> = Vec::new();
let scalar: TestScalar = (-2i64).into();
let zero = TestScalar::ZERO;
let column_a_multiplied_by_scalar: Vec<TestScalar> = [-2i64, -20, 10, 0, -20]
.iter()
.map(|bi| bi.into())
.map(core::convert::Into::into)
.collect();

let commitment_a = NaiveCommitment(column_a.clone());
Expand Down
Loading

0 comments on commit 3cc7a75

Please sign in to comment.