Fix new clippy lints in clippy nightly (#3176)

This commit is contained in:
teor 2021-12-10 00:19:14 +10:00 committed by GitHub
parent 0ad89f2f41
commit 4ce6fbccc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 34 additions and 48 deletions

View File

@ -132,24 +132,21 @@ impl Block {
pub fn sprout_nullifiers(&self) -> impl Iterator<Item = &sprout::Nullifier> { pub fn sprout_nullifiers(&self) -> impl Iterator<Item = &sprout::Nullifier> {
self.transactions self.transactions
.iter() .iter()
.map(|transaction| transaction.sprout_nullifiers()) .flat_map(|transaction| transaction.sprout_nullifiers())
.flatten()
} }
/// Access the [`sapling::Nullifier`]s from all transactions in this block. /// Access the [`sapling::Nullifier`]s from all transactions in this block.
pub fn sapling_nullifiers(&self) -> impl Iterator<Item = &sapling::Nullifier> { pub fn sapling_nullifiers(&self) -> impl Iterator<Item = &sapling::Nullifier> {
self.transactions self.transactions
.iter() .iter()
.map(|transaction| transaction.sapling_nullifiers()) .flat_map(|transaction| transaction.sapling_nullifiers())
.flatten()
} }
/// Access the [`orchard::Nullifier`]s from all transactions in this block. /// Access the [`orchard::Nullifier`]s from all transactions in this block.
pub fn orchard_nullifiers(&self) -> impl Iterator<Item = &orchard::Nullifier> { pub fn orchard_nullifiers(&self) -> impl Iterator<Item = &orchard::Nullifier> {
self.transactions self.transactions
.iter() .iter()
.map(|transaction| transaction.orchard_nullifiers()) .flat_map(|transaction| transaction.orchard_nullifiers())
.flatten()
} }
/// Count how many Sapling transactions exist in a block, /// Count how many Sapling transactions exist in a block,

View File

@ -184,7 +184,7 @@ where
.map(|tx| { .map(|tx| {
tx.as_ref() tx.as_ref()
.auth_digest() .auth_digest()
.unwrap_or_else(|| transaction::AuthDigest([0xFF; 32])) .unwrap_or(transaction::AuthDigest([0xFF; 32]))
}) })
.collect() .collect()
} }

View File

@ -92,14 +92,13 @@ impl NonAdjacentForm for pallas::Scalar {
// Construct a buffer of bits of the scalar, starting at bit `pos` // Construct a buffer of bits of the scalar, starting at bit `pos`
let u64_idx = pos / 64; let u64_idx = pos / 64;
let bit_idx = pos % 64; let bit_idx = pos % 64;
let bit_buf: u64; let bit_buf: u64 = if bit_idx < 64 - w {
if bit_idx < 64 - w {
// This window's bits are contained in a single u64 // This window's bits are contained in a single u64
bit_buf = x_u64[u64_idx] >> bit_idx; x_u64[u64_idx] >> bit_idx
} else { } else {
// Combine the current u64's bits with the bits from the next u64 // Combine the current u64's bits with the bits from the next u64
bit_buf = (x_u64[u64_idx] >> bit_idx) | (x_u64[1 + u64_idx] << (64 - bit_idx)); (x_u64[u64_idx] >> bit_idx) | (x_u64[1 + u64_idx] << (64 - bit_idx))
} };
// Add the carry into the current window // Add the carry into the current window
let window = carry + (bit_buf & window_mask); let window = carry + (bit_buf & window_mask);

View File

@ -116,12 +116,12 @@ impl NoteCommitment {
// //
// The `TryFrom<Diversifier>` impls for the `jubjub::*Point`s handles // The `TryFrom<Diversifier>` impls for the `jubjub::*Point`s handles
// calling `DiversifyHash` implicitly. // calling `DiversifyHash` implicitly.
let g_d_bytes: [u8; 32];
if let Ok(g_d) = jubjub::AffinePoint::try_from(diversifier) { let g_d_bytes: [u8; 32] = if let Ok(g_d) = jubjub::AffinePoint::try_from(diversifier) {
g_d_bytes = g_d.to_bytes(); g_d.to_bytes()
} else { } else {
return None; return None;
} };
let pk_d_bytes = <[u8; 32]>::from(transmission_key); let pk_d_bytes = <[u8; 32]>::from(transmission_key);
let v_bytes = value.to_bytes(); let v_bytes = value.to_bytes();

View File

@ -871,8 +871,7 @@ impl Transaction {
pub fn orchard_actions(&self) -> impl Iterator<Item = &orchard::Action> { pub fn orchard_actions(&self) -> impl Iterator<Item = &orchard::Action> {
self.orchard_shielded_data() self.orchard_shielded_data()
.into_iter() .into_iter()
.map(orchard::ShieldedData::actions) .flat_map(orchard::ShieldedData::actions)
.flatten()
} }
/// Access the [`orchard::Nullifier`]s in this transaction, if there are any, /// Access the [`orchard::Nullifier`]s in this transaction, if there are any,
@ -880,8 +879,7 @@ impl Transaction {
pub fn orchard_nullifiers(&self) -> impl Iterator<Item = &orchard::Nullifier> { pub fn orchard_nullifiers(&self) -> impl Iterator<Item = &orchard::Nullifier> {
self.orchard_shielded_data() self.orchard_shielded_data()
.into_iter() .into_iter()
.map(orchard::ShieldedData::nullifiers) .flat_map(orchard::ShieldedData::nullifiers)
.flatten()
} }
/// Access the note commitments in this transaction, if there are any, /// Access the note commitments in this transaction, if there are any,
@ -889,8 +887,7 @@ impl Transaction {
pub fn orchard_note_commitments(&self) -> impl Iterator<Item = &pallas::Base> { pub fn orchard_note_commitments(&self) -> impl Iterator<Item = &pallas::Base> {
self.orchard_shielded_data() self.orchard_shielded_data()
.into_iter() .into_iter()
.map(orchard::ShieldedData::note_commitments) .flat_map(orchard::ShieldedData::note_commitments)
.flatten()
} }
/// Access the [`orchard::Flags`] in this transaction, if there is any, /// Access the [`orchard::Flags`] in this transaction, if there is any,

View File

@ -847,8 +847,7 @@ pub fn transaction_to_fake_v5(
expiry_height: height, expiry_height: height,
sapling_shielded_data: sapling_shielded_data sapling_shielded_data: sapling_shielded_data
.clone() .clone()
.map(sapling_shielded_v4_to_fake_v5) .and_then(sapling_shielded_v4_to_fake_v5),
.flatten(),
orchard_shielded_data: None, orchard_shielded_data: None,
}, },
v5 @ V5 { .. } => v5.clone(), v5 @ V5 { .. } => v5.clone(),

View File

@ -34,15 +34,13 @@ impl<'a> TryFrom<&'a [u8]> for Memo {
impl fmt::Debug for Memo { impl fmt::Debug for Memo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let output: String;
// This saves work but if the 'valid utf8 string' is just a // This saves work but if the 'valid utf8 string' is just a
// bunch of numbers, it prints them out like // bunch of numbers, it prints them out like
// 'Memo("\u{0}\u{0}..")', so. ¯\_(ツ)_/¯ // 'Memo("\u{0}\u{0}..")', so. ¯\_(ツ)_/¯
match std::str::from_utf8(&self.0[..]) { let output: String = match std::str::from_utf8(&self.0[..]) {
Ok(memo) => output = String::from(memo), Ok(memo) => String::from(memo),
_ => output = hex::encode(&self.0[..]), _ => hex::encode(&self.0[..]),
} };
f.debug_tuple("Memo").field(&output).finish() f.debug_tuple("Memo").field(&output).finish()
} }

View File

@ -7,7 +7,7 @@ fn parse_coinbase_height_mins() {
// examples with height 1: // examples with height 1:
let case1 = vec![0x51]; let case1 = vec![0x51];
assert!(!parse_coinbase_height(case1.clone()).is_err()); assert!(parse_coinbase_height(case1.clone()).is_ok());
assert_eq!(parse_coinbase_height(case1).unwrap().0 .0, 1); assert_eq!(parse_coinbase_height(case1).unwrap().0 .0, 1);
let case2 = vec![0x01, 0x01]; let case2 = vec![0x01, 0x01];
@ -25,7 +25,7 @@ fn parse_coinbase_height_mins() {
// examples with height 17: // examples with height 17:
let case1 = vec![0x01, 0x11]; let case1 = vec![0x01, 0x11];
assert!(!parse_coinbase_height(case1.clone()).is_err()); assert!(parse_coinbase_height(case1.clone()).is_ok());
assert_eq!(parse_coinbase_height(case1).unwrap().0 .0, 17); assert_eq!(parse_coinbase_height(case1).unwrap().0 .0, 17);
let case2 = vec![0x02, 0x11, 0x00]; let case2 = vec![0x02, 0x11, 0x00];

View File

@ -344,9 +344,7 @@ proptest! {
// If `change` is invalid for the current MetaAddr state, skip it. // If `change` is invalid for the current MetaAddr state, skip it.
// If we've run out of changes for this addr, do nothing. // If we've run out of changes for this addr, do nothing.
if let Some(changed_addr) = change if let Some(changed_addr) = change.and_then(|change| change.apply_to_meta_addr(*addr))
.map(|change| change.apply_to_meta_addr(*addr))
.flatten()
{ {
prop_assert_eq!(changed_addr.addr, addr.addr); prop_assert_eq!(changed_addr.addr, addr.addr);
*addr = changed_addr; *addr = changed_addr;

View File

@ -157,9 +157,8 @@ impl Config {
} }
// Try the hard limit or the minimum, whichever is greater // Try the hard limit or the minimum, whichever is greater
let min_limit = if let Some(hard_limit) = let min_limit =
hard_rlimit.map(TryInto::try_into).map(Result::ok).flatten() if let Some(hard_limit) = hard_rlimit.map(TryInto::try_into).and_then(Result::ok) {
{
std::cmp::max(Config::MIN_OPEN_FILE_LIMIT, hard_limit) std::cmp::max(Config::MIN_OPEN_FILE_LIMIT, hard_limit)
} else { } else {
Config::MIN_OPEN_FILE_LIMIT Config::MIN_OPEN_FILE_LIMIT

View File

@ -473,7 +473,7 @@ impl StateService {
(max_height - 1).expect("max_len is at least 1") (max_height - 1).expect("max_len is at least 1")
}; };
let stop_height = stop.map(|hash| self.best_height_by_hash(hash)).flatten(); let stop_height = stop.and_then(|hash| self.best_height_by_hash(hash));
// Compute the final height, making sure it is: // Compute the final height, making sure it is:
// * at or below our chain tip, and // * at or below our chain tip, and

View File

@ -542,8 +542,7 @@ impl FinalizedState {
let (finalized, rsp_tx) = queued_block; let (finalized, rsp_tx) = queued_block;
let result = self.commit_finalized_direct(finalized.clone(), "CommitFinalized request"); let result = self.commit_finalized_direct(finalized.clone(), "CommitFinalized request");
let block_result; let block_result = if result.is_ok() {
if result.is_ok() {
metrics::counter!("state.checkpoint.finalized.block.count", 1); metrics::counter!("state.checkpoint.finalized.block.count", 1);
metrics::gauge!( metrics::gauge!(
"state.checkpoint.finalized.block.height", "state.checkpoint.finalized.block.height",
@ -556,7 +555,7 @@ impl FinalizedState {
metrics::gauge!("zcash.chain.verified.block.height", finalized.height.0 as _); metrics::gauge!("zcash.chain.verified.block.height", finalized.height.0 as _);
metrics::counter!("zcash.chain.verified.block.total", 1); metrics::counter!("zcash.chain.verified.block.total", 1);
block_result = Ok(finalized); Ok(finalized)
} else { } else {
metrics::counter!("state.checkpoint.error.block.count", 1); metrics::counter!("state.checkpoint.error.block.count", 1);
metrics::gauge!( metrics::gauge!(
@ -564,8 +563,8 @@ impl FinalizedState {
finalized.height.0 as _ finalized.height.0 as _
); );
block_result = Err(()); Err(())
} };
let _ = rsp_tx.send(result.map_err(Into::into)); let _ = rsp_tx.send(result.map_err(Into::into));