f5412e2aa2 Fix clippy warnings (Tobin C. Harding)

Pull request description:

  Clippy recently upgraded and a few two new warnings types popped up in our codebase, fix them both in a single patch so CI passes for all commits.

  1. Remove unneeded explicit borrow
  2. Use `if let Some` instead of pattern match

ACKs for top commit:
  apoelstra:
    ACK f5412e2aa2
  Kixunil:
    ACK f5412e2aa2

Tree-SHA512: 1faeb6173061e28a1acfe1a37a669982abbd832b327448e31648c447a7d043841edf30349700ff9da9dd330cfa6d497d188534daab825069e4489653e25987ca
This commit is contained in:
Andrew Poelstra 2022-09-26 18:01:59 +00:00
commit 7228d1fc14
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 11 additions and 14 deletions

View File

@ -730,25 +730,25 @@ impl Decodable for CheckedData {
// References // References
impl<'a, T: Encodable> Encodable for &'a T { impl<'a, T: Encodable> Encodable for &'a T {
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> { fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
(&**self).consensus_encode(w) (**self).consensus_encode(w)
} }
} }
impl<'a, T: Encodable> Encodable for &'a mut T { impl<'a, T: Encodable> Encodable for &'a mut T {
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> { fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
(&**self).consensus_encode(w) (**self).consensus_encode(w)
} }
} }
impl<T: Encodable> Encodable for rc::Rc<T> { impl<T: Encodable> Encodable for rc::Rc<T> {
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> { fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
(&**self).consensus_encode(w) (**self).consensus_encode(w)
} }
} }
impl<T: Encodable> Encodable for sync::Arc<T> { impl<T: Encodable> Encodable for sync::Arc<T> {
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> { fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
(&**self).consensus_encode(w) (**self).consensus_encode(w)
} }
} }

View File

@ -302,7 +302,7 @@ impl Decodable for PartiallySignedTransaction {
global.unsigned_tx_checks()?; global.unsigned_tx_checks()?;
let inputs: Vec<Input> = { let inputs: Vec<Input> = {
let inputs_len: usize = (&global.unsigned_tx.input).len(); let inputs_len: usize = global.unsigned_tx.input.len();
let mut inputs: Vec<Input> = Vec::with_capacity(inputs_len); let mut inputs: Vec<Input> = Vec::with_capacity(inputs_len);
@ -314,7 +314,7 @@ impl Decodable for PartiallySignedTransaction {
}; };
let outputs: Vec<Output> = { let outputs: Vec<Output> = {
let outputs_len: usize = (&global.unsigned_tx.output).len(); let outputs_len: usize = global.unsigned_tx.output.len();
let mut outputs: Vec<Output> = Vec::with_capacity(outputs_len); let mut outputs: Vec<Output> = Vec::with_capacity(outputs_len);
@ -818,7 +818,7 @@ mod tests {
assert_eq!(psbt.outputs.len(), 2); assert_eq!(psbt.outputs.len(), 2);
let tx_input = &psbt.unsigned_tx.input[0]; let tx_input = &psbt.unsigned_tx.input[0];
let psbt_non_witness_utxo = (&psbt.inputs[0].non_witness_utxo).as_ref().unwrap(); let psbt_non_witness_utxo = psbt.inputs[0].non_witness_utxo.as_ref().unwrap();
assert_eq!(tx_input.previous_output.txid, psbt_non_witness_utxo.txid()); assert_eq!(tx_input.previous_output.txid, psbt_non_witness_utxo.txid());
assert!(psbt_non_witness_utxo.output[tx_input.previous_output.vout as usize] assert!(psbt_non_witness_utxo.output[tx_input.previous_output.vout as usize]
@ -826,7 +826,7 @@ mod tests {
.is_p2pkh() .is_p2pkh()
); );
assert_eq!( assert_eq!(
(&psbt.inputs[0].sighash_type).as_ref().unwrap().ecdsa_hash_ty().unwrap(), psbt.inputs[0].sighash_type.as_ref().unwrap().ecdsa_hash_ty().unwrap(),
EcdsaSighashType::All EcdsaSighashType::All
); );
} }

View File

@ -282,13 +282,10 @@ impl TaprootSpendInfo {
for leaves in node.leaves { for leaves in node.leaves {
let key = (leaves.script, leaves.ver); let key = (leaves.script, leaves.ver);
let value = leaves.merkle_branch; let value = leaves.merkle_branch;
match info.script_map.get_mut(&key) { if let Some(set) = info.script_map.get_mut(&key) {
Some(set) => {
set.insert(value); set.insert(value);
continue; // NLL fix continue; // NLL fix
} }
None => {}
}
let mut set = BTreeSet::new(); let mut set = BTreeSet::new();
set.insert(value); set.insert(value);
info.script_map.insert(key, set); info.script_map.insert(key, set);