Skip to content

Commit 03c6587

Browse files
committed
Remove unneeded explicit reference
Clippy emits a bunch of warnings of the form warning: this expression borrows a reference (`&Self`) that is immediately dereferenced by the compiler As suggested, remove the unneeded explicit reference.
1 parent 952af97 commit 03c6587

File tree

13 files changed

+43
-43
lines changed

13 files changed

+43
-43
lines changed

src/descriptor/bare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ where
111111
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
112112
{
113113
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
114-
let sub = Miniscript::<Pk, BareCtx>::from_tree(&top)?;
114+
let sub = Miniscript::<Pk, BareCtx>::from_tree(top)?;
115115
BareCtx::top_level_checks(&sub)?;
116116
Bare::new(sub)
117117
}

src/descriptor/key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ impl DescriptorXKey<bip32::ExtendedPrivKey> {
172172

173173
let xprv = self
174174
.xkey
175-
.derive_priv(&secp, &hardened_path)
175+
.derive_priv(secp, &hardened_path)
176176
.map_err(|_| DescriptorKeyParseError("Unable to derive the hardened steps"))?;
177-
let xpub = bip32::ExtendedPubKey::from_priv(&secp, &xprv);
177+
let xpub = bip32::ExtendedPubKey::from_priv(secp, &xprv);
178178

179179
let origin = match &self.origin {
180180
Some((fingerprint, path)) => Some((
@@ -188,7 +188,7 @@ impl DescriptorXKey<bip32::ExtendedPrivKey> {
188188
if hardened_path.is_empty() {
189189
None
190190
} else {
191-
Some((self.xkey.fingerprint(&secp), hardened_path.into()))
191+
Some((self.xkey.fingerprint(secp), hardened_path.into()))
192192
}
193193
}
194194
};

src/descriptor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ impl Descriptor<DescriptorPublicKey> {
712712
key_map: &mut KeyMap|
713713
-> Result<DescriptorPublicKey, DescriptorKeyParseError> {
714714
let (public_key, secret_key) = match DescriptorSecretKey::from_str(s) {
715-
Ok(sk) => (sk.to_public(&secp)?, Some(sk)),
715+
Ok(sk) => (sk.to_public(secp)?, Some(sk)),
716716
Err(_) => (DescriptorPublicKey::from_str(s)?, None),
717717
};
718718

@@ -774,7 +774,7 @@ impl Descriptor<DescriptorPublicKey> {
774774
let range = if self.is_deriveable() { range } else { 0..1 };
775775

776776
for i in range {
777-
let concrete = self.derived_descriptor(&secp, i)?;
777+
let concrete = self.derived_descriptor(secp, i)?;
778778
if &concrete.script_pubkey() == script_pubkey {
779779
return Ok(Some((i, concrete)));
780780
}

src/descriptor/pretaproot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ pub(crate) mod traits {
259259
{
260260
// This expect can technically be avoided if we implement this for types, but
261261
// having this expect saves lots of LoC because of default implementation
262-
<Self as DescriptorTrait<Pk>>::explicit_script(&self)
262+
<Self as DescriptorTrait<Pk>>::explicit_script(self)
263263
.expect("Pre taproot descriptor have explicit script")
264264
}
265265

@@ -269,7 +269,7 @@ pub(crate) mod traits {
269269
where
270270
Pk: ToPublicKey,
271271
{
272-
<Self as DescriptorTrait<Pk>>::script_code(&self)
272+
<Self as DescriptorTrait<Pk>>::script_code(self)
273273
.expect("Pre taproot descriptor have non-failing script code")
274274
}
275275
}

src/descriptor/segwitv0.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ where
140140
let top = &top.args[0];
141141
if top.name == "sortedmulti" {
142142
return Ok(Wsh {
143-
inner: WshInner::SortedMulti(SortedMultiVec::from_tree(&top)?),
143+
inner: WshInner::SortedMulti(SortedMultiVec::from_tree(top)?),
144144
});
145145
}
146-
let sub = Miniscript::from_tree(&top)?;
146+
let sub = Miniscript::from_tree(top)?;
147147
Segwitv0::top_level_checks(&sub)?;
148148
Ok(Wsh {
149149
inner: WshInner::Ms(sub),

src/descriptor/sh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ where
103103
if top.name == "sh" && top.args.len() == 1 {
104104
let top = &top.args[0];
105105
let inner = match top.name {
106-
"wsh" => ShInner::Wsh(Wsh::from_tree(&top)?),
107-
"wpkh" => ShInner::Wpkh(Wpkh::from_tree(&top)?),
108-
"sortedmulti" => ShInner::SortedMulti(SortedMultiVec::from_tree(&top)?),
106+
"wsh" => ShInner::Wsh(Wsh::from_tree(top)?),
107+
"wpkh" => ShInner::Wpkh(Wpkh::from_tree(top)?),
108+
"sortedmulti" => ShInner::SortedMulti(SortedMultiVec::from_tree(top)?),
109109
_ => {
110-
let sub = Miniscript::from_tree(&top)?;
110+
let sub = Miniscript::from_tree(top)?;
111111
Legacy::top_level_checks(&sub)?;
112112
ShInner::Ms(sub)
113113
}

src/descriptor/tr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ where
322322
let (depth, last) = self.stack.pop().expect("Size checked above");
323323
match &*last {
324324
TapTree::Tree(l, r) => {
325-
self.stack.push((depth + 1, &r));
326-
self.stack.push((depth + 1, &l));
325+
self.stack.push((depth + 1, r));
326+
self.stack.push((depth + 1, l));
327327
}
328328
TapTree::Leaf(ref ms) => return Some((depth, ms)),
329329
}
@@ -533,7 +533,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for TapTree<Pk> {
533533
}
534534
}
535535

536-
let pol = lift_helper(&self)?;
536+
let pol = lift_helper(self)?;
537537
Ok(pol.normalized())
538538
}
539539
}
@@ -594,15 +594,15 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Tr<Pk> {
594594
Pk: ToPublicKey,
595595
S: Satisfier<Pk>,
596596
{
597-
best_tap_spend(&self, satisfier, false /* allow_mall */)
597+
best_tap_spend(self, satisfier, false /* allow_mall */)
598598
}
599599

600600
fn get_satisfaction_mall<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
601601
where
602602
Pk: ToPublicKey,
603603
S: Satisfier<Pk>,
604604
{
605-
best_tap_spend(&self, satisfier, true /* allow_mall */)
605+
best_tap_spend(self, satisfier, true /* allow_mall */)
606606
}
607607

608608
fn max_satisfaction_weight(&self) -> Result<usize, Error> {

src/interpreter/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ impl<'txin> Interpreter<'txin> {
254254
let script_pubkey = self.script_code.as_ref().expect("Legacy have script code");
255255
let sighash = if self.is_legacy() {
256256
let sighash_u32 = ecdsa_sig.hash_ty.to_u32();
257-
cache.legacy_signature_hash(input_idx, &script_pubkey, sighash_u32)
257+
cache.legacy_signature_hash(input_idx, script_pubkey, sighash_u32)
258258
} else if self.is_segwit_v0() {
259259
let amt = match get_prevout(prevouts, input_idx) {
260260
Some(txout) => txout.borrow().value,
261261
None => return false,
262262
};
263-
cache.segwit_signature_hash(input_idx, &script_pubkey, amt, ecdsa_sig.hash_ty)
263+
cache.segwit_signature_hash(input_idx, script_pubkey, amt, ecdsa_sig.hash_ty)
264264
} else {
265265
// taproot(or future) signatures in segwitv0 context
266266
return false;
@@ -280,7 +280,7 @@ impl<'txin> Interpreter<'txin> {
280280
of script code for script spend",
281281
);
282282
let leaf_hash = taproot::TapLeafHash::from_script(
283-
&tap_script,
283+
tap_script,
284284
taproot::LeafVersion::TapScript,
285285
);
286286
cache.taproot_script_spend_signature_hash(
@@ -296,7 +296,7 @@ impl<'txin> Interpreter<'txin> {
296296
let msg =
297297
sighash_msg.map(|hash| secp256k1::Message::from_slice(&hash).expect("32 byte"));
298298
let success =
299-
msg.map(|msg| secp.verify_schnorr(&schnorr_sig.sig, &msg, &xpk).is_ok());
299+
msg.map(|msg| secp.verify_schnorr(&schnorr_sig.sig, &msg, xpk).is_ok());
300300
success.unwrap_or(false) // unwrap_or_default checks for errors, while success would have checksig results
301301
}
302302
}
@@ -975,7 +975,7 @@ where
975975
//Pk based descriptor
976976
if let Some(pk) = self.public_key {
977977
if let Some(stack::Element::Push(sig)) = self.stack.pop() {
978-
if let Ok(key_sig) = verify_sersig(&mut self.verify_sig, &pk, &sig) {
978+
if let Ok(key_sig) = verify_sersig(&mut self.verify_sig, pk, sig) {
979979
//Signature check successful, set public_key to None to
980980
//terminate the next() function in the subsequent call
981981
self.public_key = None;

src/miniscript/analyzable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
8383
// It maybe possible to return a detail error type containing why the miniscript
8484
// failed. But doing so may require returning a collection of errors
8585
pub fn within_resource_limits(&self) -> bool {
86-
match Ctx::check_local_validity(&self) {
86+
match Ctx::check_local_validity(self) {
8787
Ok(_) => true,
8888
Err(_) => false,
8989
}

src/miniscript/astelem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
659659
Terminal::PkH(ref hash) => builder
660660
.push_opcode(opcodes::all::OP_DUP)
661661
.push_opcode(opcodes::all::OP_HASH160)
662-
.push_slice(&Pk::hash_to_hash160(&hash)[..])
662+
.push_slice(&Pk::hash_to_hash160(hash)[..])
663663
.push_opcode(opcodes::all::OP_EQUALVERIFY),
664664
Terminal::After(t) => builder
665665
.push_int(t as i64)

src/miniscript/lex.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ pub fn lex<'s>(script: &'s script::Script) -> Result<Vec<Token<'s>>, Error> {
226226
}
227227
script::Instruction::PushBytes(bytes) => {
228228
match bytes.len() {
229-
20 => ret.push(Token::Hash20(&bytes)),
230-
32 => ret.push(Token::Bytes32(&bytes)),
231-
33 => ret.push(Token::Bytes33(&bytes)),
232-
65 => ret.push(Token::Bytes65(&bytes)),
229+
20 => ret.push(Token::Hash20(bytes)),
230+
32 => ret.push(Token::Bytes32(bytes)),
231+
33 => ret.push(Token::Bytes33(bytes)),
232+
65 => ret.push(Token::Bytes65(bytes)),
233233
_ => {
234234
match script::read_scriptint(bytes) {
235235
Ok(v) if v >= 0 => {

src/psbt/finalizer.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub(super) fn get_scriptpubkey(psbt: &Psbt, index: usize) -> Result<&Script, Inp
106106
pub(super) fn get_utxo(psbt: &Psbt, index: usize) -> Result<&bitcoin::TxOut, InputError> {
107107
let inp = &psbt.inputs[index];
108108
let utxo = if let Some(ref witness_utxo) = inp.witness_utxo {
109-
&witness_utxo
109+
witness_utxo
110110
} else if let Some(ref non_witness_utxo) = inp.non_witness_utxo {
111111
let vout = psbt.unsigned_tx.input[index].previous_output.vout;
112112
&non_witness_utxo.output[vout as usize]
@@ -278,7 +278,7 @@ pub fn interpreter_check<C: secp256k1::Verification>(
278278
psbt: &Psbt,
279279
secp: &Secp256k1<C>,
280280
) -> Result<(), Error> {
281-
let utxos = prevouts(&psbt)?;
281+
let utxos = prevouts(psbt)?;
282282
let utxos = &Prevouts::All(&utxos);
283283
for (index, input) in psbt.inputs.iter().enumerate() {
284284
let empty_script_sig = Script::new();
@@ -290,7 +290,7 @@ pub fn interpreter_check<C: secp256k1::Verification>(
290290
.map(|wit_slice| Witness::from_vec(wit_slice.to_vec())) // TODO: Update rust-bitcoin psbt API to use witness
291291
.unwrap_or(empty_witness);
292292

293-
interpreter_inp_check(psbt, secp, index, utxos, &witness, &script_sig)?;
293+
interpreter_inp_check(psbt, secp, index, utxos, &witness, script_sig)?;
294294
}
295295
Ok(())
296296
}
@@ -313,9 +313,9 @@ fn interpreter_inp_check<C: secp256k1::Verification, T: Borrow<TxOut>>(
313313
let cltv = psbt.unsigned_tx.lock_time;
314314
let csv = psbt.unsigned_tx.input[index].sequence;
315315
let interpreter =
316-
interpreter::Interpreter::from_txdata(spk, &script_sig, &witness, cltv, csv)
316+
interpreter::Interpreter::from_txdata(spk, script_sig, witness, cltv, csv)
317317
.map_err(|e| Error::InputError(InputError::Interpreter(e), index))?;
318-
let iter = interpreter.iter(secp, &psbt.unsigned_tx, index, &utxos);
318+
let iter = interpreter.iter(secp, &psbt.unsigned_tx, index, utxos);
319319
if let Some(error) = iter.filter_map(Result::err).next() {
320320
return Err(Error::InputError(InputError::Interpreter(error), index));
321321
};
@@ -373,7 +373,7 @@ fn finalize_input_helper<C: secp256k1::Verification>(
373373
) -> Result<(Witness, Script), super::Error> {
374374
let (witness, script_sig) = {
375375
let spk = get_scriptpubkey(psbt, index).map_err(|e| Error::InputError(e, index))?;
376-
let sat = PsbtInputSatisfier::new(&psbt, index);
376+
let sat = PsbtInputSatisfier::new(psbt, index);
377377

378378
if spk.is_v1_p2tr() {
379379
// Deal with tr case separately, unfortunately we cannot infer the full descriptor for Tr
@@ -382,10 +382,10 @@ fn finalize_input_helper<C: secp256k1::Verification>(
382382
(wit, Script::new())
383383
} else {
384384
// Get a descriptor for this input.
385-
let desc = get_descriptor(&psbt, index).map_err(|e| Error::InputError(e, index))?;
385+
let desc = get_descriptor(psbt, index).map_err(|e| Error::InputError(e, index))?;
386386

387387
//generate the satisfaction witness and scriptsig
388-
let sat = PsbtInputSatisfier::new(&psbt, index);
388+
let sat = PsbtInputSatisfier::new(psbt, index);
389389
if !allow_mall {
390390
desc.get_satisfaction(sat)
391391
} else {
@@ -396,7 +396,7 @@ fn finalize_input_helper<C: secp256k1::Verification>(
396396
};
397397

398398
let witness = bitcoin::Witness::from_vec(witness);
399-
let utxos = prevouts(&psbt)?;
399+
let utxos = prevouts(psbt)?;
400400
let utxos = &Prevouts::All(&utxos);
401401
interpreter_inp_check(psbt, secp, index, utxos, &witness, &script_sig)?;
402402

src/psbt/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<'psbt, Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfie
363363
fn try_vec_as_preimage32(vec: &Vec<u8>) -> Option<Preimage32> {
364364
if vec.len() == 32 {
365365
let mut arr = [0u8; 32];
366-
arr.copy_from_slice(&vec);
366+
arr.copy_from_slice(vec);
367367
Some(arr)
368368
} else {
369369
None
@@ -763,7 +763,7 @@ impl PsbtExt for Psbt {
763763
};
764764

765765
let (_, spk_check_passed) =
766-
update_input_with_descriptor_helper(input, &desc, Some(expected_spk))
766+
update_input_with_descriptor_helper(input, desc, Some(expected_spk))
767767
.map_err(UtxoUpdateError::DerivationError)?;
768768

769769
if !spk_check_passed {
@@ -831,7 +831,7 @@ impl PsbtExt for Psbt {
831831
.unwrap_or(false);
832832
if inp_spk.is_v0_p2wpkh() || inp_spk.is_v0_p2wsh() || is_nested_wpkh || is_nested_wsh {
833833
let msg = if inp_spk.is_v0_p2wpkh() {
834-
let script_code = script_code_wpkh(&inp_spk);
834+
let script_code = script_code_wpkh(inp_spk);
835835
cache.segwit_signature_hash(idx, &script_code, amt, hash_ty)?
836836
} else if is_nested_wpkh {
837837
let script_code = script_code_wpkh(
@@ -852,7 +852,7 @@ impl PsbtExt for Psbt {
852852
} else {
853853
// legacy sighash case
854854
let script_code = if inp_spk.is_p2sh() {
855-
&inp.redeem_script
855+
inp.redeem_script
856856
.as_ref()
857857
.ok_or(SighashError::MissingRedeemScript)?
858858
} else {

0 commit comments

Comments
 (0)