From 56b577b31eba34dc501f8ae95025a48071e623fb Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sat, 27 Mar 2021 18:33:39 +1300 Subject: [PATCH] clippy: Fix small lints --- components/zcash_note_encryption/src/lib.rs | 1 + zcash_client_backend/src/zip321.rs | 6 +++--- zcash_history/src/node_data.rs | 6 ++++-- zcash_history/src/tree.rs | 4 ++-- zcash_primitives/src/transaction/components/amount.rs | 2 +- zcash_primitives/src/transaction/sighash.rs | 8 ++++---- zcash_primitives/src/zip32.rs | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/components/zcash_note_encryption/src/lib.rs b/components/zcash_note_encryption/src/lib.rs index 31e1bb209..0ee39e7ab 100644 --- a/components/zcash_note_encryption/src/lib.rs +++ b/components/zcash_note_encryption/src/lib.rs @@ -1,5 +1,6 @@ #[cfg(test)] mod tests { + #[allow(clippy::eq_op)] #[test] fn it_works() { assert_eq!(2 + 2, 4); diff --git a/zcash_client_backend/src/zip321.rs b/zcash_client_backend/src/zip321.rs index 801cb009d..bc2d8300b 100644 --- a/zcash_client_backend/src/zip321.rs +++ b/zcash_client_backend/src/zip321.rs @@ -80,9 +80,9 @@ impl Payment { /// internally, so payments must be normalized prior to being passed to the comparison function /// returned from this method. #[cfg(any(test, feature = "test-dependencies"))] - pub(in crate::zip321) fn compare_normalized<'a, P: consensus::Parameters>( - params: &'a P, - ) -> impl Fn(&Payment, &Payment) -> Ordering + 'a { + pub(in crate::zip321) fn compare_normalized( + params: &P, + ) -> impl Fn(&Payment, &Payment) -> Ordering + '_ { move |a: &Payment, b: &Payment| { let a_addr = a.recipient_address.encode(params); let b_addr = b.recipient_address.encode(params); diff --git a/zcash_history/src/node_data.rs b/zcash_history/src/node_data.rs index 8e1f10440..0c93c9f78 100644 --- a/zcash_history/src/node_data.rs +++ b/zcash_history/src/node_data.rs @@ -207,8 +207,10 @@ impl NodeData { #[cfg(test)] impl quickcheck::Arbitrary for NodeData { fn arbitrary(gen: &mut G) -> Self { - let mut node_data = NodeData::default(); - node_data.consensus_branch_id = 0; + let mut node_data = NodeData { + consensus_branch_id: 0, + ..Default::default() + }; gen.fill_bytes(&mut node_data.subtree_commitment[..]); node_data.start_time = gen.next_u32(); node_data.end_time = gen.next_u32(); diff --git a/zcash_history/src/tree.rs b/zcash_history/src/tree.rs index 71daa1144..666623741 100644 --- a/zcash_history/src/tree.rs +++ b/zcash_history/src/tree.rs @@ -651,7 +651,7 @@ mod tests { } fn leaf_count(number: u32) -> TestResult { - if number > 1024 * 1024 || number < 3 { + if !(3..=1024 * 1024).contains(&number) { TestResult::discard() } else { let mut tree = initial(); @@ -666,7 +666,7 @@ mod tests { } fn parity(number: u32) -> TestResult { - if number > 2048 * 2048 || number < 3 { + if !(3..=2048 * 2048).contains(&number) { TestResult::discard() } else { let mut tree = initial(); diff --git a/zcash_primitives/src/transaction/components/amount.rs b/zcash_primitives/src/transaction/components/amount.rs index f46c0b820..f47b485f7 100644 --- a/zcash_primitives/src/transaction/components/amount.rs +++ b/zcash_primitives/src/transaction/components/amount.rs @@ -41,7 +41,7 @@ impl Amount { /// /// Returns an error if the amount is outside the range `{0..MAX_MONEY}`. pub fn from_nonnegative_i64(amount: i64) -> Result { - if 0 <= amount && amount <= MAX_MONEY { + if (0..=MAX_MONEY).contains(&amount) { Ok(Amount(amount)) } else { Err(()) diff --git a/zcash_primitives/src/transaction/sighash.rs b/zcash_primitives/src/transaction/sighash.rs index 7189e6d7f..604e33b2f 100644 --- a/zcash_primitives/src/transaction/sighash.rs +++ b/zcash_primitives/src/transaction/sighash.rs @@ -227,11 +227,11 @@ impl<'a> SignableInput<'a> { } } -pub fn signature_hash_data<'a>( +pub fn signature_hash_data( tx: &TransactionData, consensus_branch_id: consensus::BranchId, hash_type: u32, - signable_input: SignableInput<'a>, + signable_input: SignableInput<'_>, ) -> Vec { if has_overwinter_components(&tx.version) { let mut personal = [0; 16]; @@ -372,11 +372,11 @@ pub fn signature_hash_data<'a>( } } -pub fn signature_hash<'a>( +pub fn signature_hash( tx: &Transaction, consensus_branch_id: consensus::BranchId, hash_type: u32, - signable_input: SignableInput<'a>, + signable_input: SignableInput<'_>, ) -> Vec { signature_hash_data(tx, consensus_branch_id, hash_type, signable_input) } diff --git a/zcash_primitives/src/zip32.rs b/zcash_primitives/src/zip32.rs index ec957a918..8fb1ee402 100644 --- a/zcash_primitives/src/zip32.rs +++ b/zcash_primitives/src/zip32.rs @@ -586,7 +586,7 @@ mod tests { d1: Option<[u8; 11]>, d2: Option<[u8; 11]>, dmax: Option<[u8; 11]>, - }; + } // From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_zip32.py let test_vectors = vec![