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

View File

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

View File

@ -92,14 +92,13 @@ impl NonAdjacentForm for pallas::Scalar {
// Construct a buffer of bits of the scalar, starting at bit `pos`
let u64_idx = pos / 64;
let bit_idx = pos % 64;
let bit_buf: u64;
if bit_idx < 64 - w {
let bit_buf: u64 = if bit_idx < 64 - w {
// 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 {
// 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
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
// calling `DiversifyHash` implicitly.
let g_d_bytes: [u8; 32];
if let Ok(g_d) = jubjub::AffinePoint::try_from(diversifier) {
g_d_bytes = g_d.to_bytes();
let g_d_bytes: [u8; 32] = if let Ok(g_d) = jubjub::AffinePoint::try_from(diversifier) {
g_d.to_bytes()
} else {
return None;
}
};
let pk_d_bytes = <[u8; 32]>::from(transmission_key);
let v_bytes = value.to_bytes();

View File

@ -871,8 +871,7 @@ impl Transaction {
pub fn orchard_actions(&self) -> impl Iterator<Item = &orchard::Action> {
self.orchard_shielded_data()
.into_iter()
.map(orchard::ShieldedData::actions)
.flatten()
.flat_map(orchard::ShieldedData::actions)
}
/// 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> {
self.orchard_shielded_data()
.into_iter()
.map(orchard::ShieldedData::nullifiers)
.flatten()
.flat_map(orchard::ShieldedData::nullifiers)
}
/// 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> {
self.orchard_shielded_data()
.into_iter()
.map(orchard::ShieldedData::note_commitments)
.flatten()
.flat_map(orchard::ShieldedData::note_commitments)
}
/// 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,
sapling_shielded_data: sapling_shielded_data
.clone()
.map(sapling_shielded_v4_to_fake_v5)
.flatten(),
.and_then(sapling_shielded_v4_to_fake_v5),
orchard_shielded_data: None,
},
v5 @ V5 { .. } => v5.clone(),

View File

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

View File

@ -7,7 +7,7 @@ fn parse_coinbase_height_mins() {
// examples with height 1:
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);
let case2 = vec![0x01, 0x01];
@ -25,7 +25,7 @@ fn parse_coinbase_height_mins() {
// examples with height 17:
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);
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 we've run out of changes for this addr, do nothing.
if let Some(changed_addr) = change
.map(|change| change.apply_to_meta_addr(*addr))
.flatten()
if let Some(changed_addr) = change.and_then(|change| change.apply_to_meta_addr(*addr))
{
prop_assert_eq!(changed_addr.addr, addr.addr);
*addr = changed_addr;

View File

@ -157,13 +157,12 @@ impl Config {
}
// Try the hard limit or the minimum, whichever is greater
let min_limit = if let Some(hard_limit) =
hard_rlimit.map(TryInto::try_into).map(Result::ok).flatten()
{
std::cmp::max(Config::MIN_OPEN_FILE_LIMIT, hard_limit)
} else {
Config::MIN_OPEN_FILE_LIMIT
};
let min_limit =
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)
} else {
Config::MIN_OPEN_FILE_LIMIT
};
if let Ok(actual_limit) = Config::set_open_file_limit(min_limit, hard_rlimit, old_limit) {
tracing::warn!(?actual_limit,
?hard_rlimit,

View File

@ -473,7 +473,7 @@ impl StateService {
(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:
// * at or below our chain tip, and

View File

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