Skip to content

Commit 8bd4f7d

Browse files
committed
clippy: non-reference stuff
As in #835, I changed a test function that used 'A'..'Z' to use an inclusive range, which is behavior-changing, and changed the impl of OrdF64::partial_cmp to be correct. Everything else is just syntactic. I apologize for structuring this PR very differently from #835 so you can't really range-diff. I tried rebasing and there were so many conflicts that I simply redid the whole thing, and since I had some experience I made some different decisions about what order to take things in.
1 parent 743a64e commit 8bd4f7d

File tree

22 files changed

+91
-142
lines changed

22 files changed

+91
-142
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ base64 = ["bitcoin/base64"]
2525
[dependencies]
2626
bitcoin = { version = "0.30.0", default-features = false }
2727
hashbrown = { version = "0.11", optional = true }
28-
internals = { package = "bitcoin-private", version = "0.1.0", default_features = false }
28+
internals = { package = "bitcoin-private", version = "0.1.0", default-features = false }
2929

3030
# Do NOT use this as a feature! Use the `serde` feature instead.
3131
actual-serde = { package = "serde", version = "1.0.103", optional = true }

bitcoind-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ miniscript = {path = "../"}
1212
bitcoind = { version = "0.30.0" }
1313
actual-rand = { package = "rand", version = "0.8.4"}
1414
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
15-
internals = { package = "bitcoin-private", version = "0.1.0", default_features = false }
15+
internals = { package = "bitcoin-private", version = "0.1.0", default-features = false }

clippy.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
msrv = "1.41.1"
2+
# PSBT API returns Self as an error type for an large-ish enum
3+
large-error-threshold = 512
4+
# A couple tests have huge tuples instead of structs. This is fixed
5+
# in a later major rev. For now we just turn down the lint.
6+
type-complexity-threshold = 1000
7+
# Some internal compiler functions take a gazillion arguments. Again,
8+
# this is fixed in a later major rev so just turn down the lint here.
9+
too-many-arguments-threshold = 9

examples/psbt_sign_finalize.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ fn main() {
9797

9898
let (outpoint, witness_utxo) = get_vout(&depo_tx, &bridge_descriptor.script_pubkey());
9999

100-
let mut txin = TxIn::default();
101-
txin.previous_output = outpoint;
102-
103-
txin.sequence = Sequence::from_height(26); //Sequence::MAX; //
100+
let txin = TxIn {
101+
previous_output: outpoint,
102+
sequence: Sequence::from_height(26),
103+
..TxIn::default()
104+
};
104105
psbt.unsigned_tx.input.push(txin);
105106

106107
psbt.unsigned_tx.output.push(TxOut {
@@ -147,13 +148,9 @@ fn main() {
147148
let pk2 = backup2_private.public_key(&secp256k1);
148149
assert!(secp256k1.verify_ecdsa(&msg, &sig2, &pk2.inner).is_ok());
149150

150-
psbt.inputs[0].partial_sigs.insert(
151-
pk1,
152-
bitcoin::ecdsa::Signature {
153-
sig: sig1,
154-
hash_ty: hash_ty,
155-
},
156-
);
151+
psbt.inputs[0]
152+
.partial_sigs
153+
.insert(pk1, bitcoin::ecdsa::Signature { sig: sig1, hash_ty });
157154

158155
println!("{:#?}", psbt);
159156

examples/taproot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ fn hardcoded_xonlypubkeys() -> Vec<XOnlyPublicKey> {
138138
],
139139
];
140140
let mut keys: Vec<XOnlyPublicKey> = vec![];
141-
for idx in 0..4 {
142-
keys.push(XOnlyPublicKey::from_slice(&serialized_keys[idx][..]).unwrap());
141+
for key in &serialized_keys {
142+
keys.push(XOnlyPublicKey::from_slice(key).unwrap());
143143
}
144144
keys
145145
}

examples/verify_tx.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,12 @@ fn main() {
5858

5959
for elem in interpreter.iter_assume_sigs() {
6060
// Don't bother checking signatures.
61-
match elem.expect("no evaluation error") {
62-
miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig } => {
63-
let (key, sig) = key_sig
64-
.as_ecdsa()
65-
.expect("expected ecdsa sig, found schnorr sig");
66-
67-
println!("Signed with:\n key: {}\n sig: {}", key, sig);
68-
}
69-
_ => {}
61+
if let Ok(miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig }) = elem {
62+
let (key, sig) = key_sig
63+
.as_ecdsa()
64+
.expect("expected ecdsa sig, found schnorr sig");
65+
66+
println!("Signed with:\n key: {}\n sig: {}", key, sig);
7067
}
7168
}
7269

@@ -83,12 +80,9 @@ fn main() {
8380
let prevouts = sighash::Prevouts::All::<bitcoin::TxOut>(&[]);
8481

8582
for elem in interpreter.iter(&secp, &tx, 0, &prevouts) {
86-
match elem.expect("no evaluation error") {
87-
miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig } => {
88-
let (key, sig) = key_sig.as_ecdsa().unwrap();
89-
println!("Signed with:\n key: {}\n sig: {}", key, sig);
90-
}
91-
_ => {}
83+
if let Ok(miniscript::interpreter::SatisfiedConstraint::PublicKey { key_sig }) = elem {
84+
let (key, sig) = key_sig.as_ecdsa().unwrap();
85+
println!("Signed with:\n key: {}\n sig: {}", key, sig);
9286
}
9387
}
9488

src/descriptor/bare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ where
192192
where
193193
T: Translator<P, Q, E>,
194194
{
195-
Ok(Bare::new(self.ms.translate_pk(t)?).map_err(TranslateErr::OuterError)?)
195+
Bare::new(self.ms.translate_pk(t)?).map_err(TranslateErr::OuterError)
196196
}
197197
}
198198

src/descriptor/key.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,7 @@ fn parse_xkey_deriv<K: InnerXKey>(
861861
// step all the vectors of indexes contain a single element. If it did though, one of the
862862
// vectors contains more than one element.
863863
// Now transform this list of vectors of steps into distinct derivation paths.
864-
.fold(Ok(Vec::new()), |paths, index_list| {
865-
let mut paths = paths?;
864+
.try_fold(Vec::new(), |mut paths, index_list| {
866865
let mut index_list = index_list?.into_iter();
867866
let first_index = index_list
868867
.next()
@@ -951,9 +950,7 @@ impl<K: InnerXKey> DescriptorXKey<K> {
951950
let (compare_fingerprint, compare_path) = match self.origin {
952951
Some((fingerprint, ref path)) => (
953952
fingerprint,
954-
path.into_iter()
955-
.chain(self.derivation_path.into_iter())
956-
.collect(),
953+
path.into_iter().chain(&self.derivation_path).collect(),
957954
),
958955
None => (
959956
self.xkey.xkey_fingerprint(secp),

src/descriptor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ impl Descriptor<DescriptorPublicKey> {
776776
///
777777
/// For multipath descriptors it will return as many descriptors as there is
778778
/// "parallel" paths. For regular descriptors it will just return itself.
779-
#[allow(clippy::blocks_in_if_conditions)]
779+
#[allow(clippy::blocks_in_conditions)]
780780
pub fn into_single_descriptors(self) -> Result<Vec<Descriptor<DescriptorPublicKey>>, Error> {
781781
// All single-path descriptors contained in this descriptor.
782782
let mut descriptors = Vec::new();

src/descriptor/tr.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ impl<Pk: MiniscriptKey> Eq for Tr<Pk> {}
8282

8383
impl<Pk: MiniscriptKey> PartialOrd for Tr<Pk> {
8484
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
85-
match self.internal_key.partial_cmp(&other.internal_key) {
86-
Some(cmp::Ordering::Equal) => {}
87-
ord => return ord,
88-
}
89-
self.tree.partial_cmp(&other.tree)
85+
Some(self.cmp(other))
9086
}
9187
}
9288

@@ -405,8 +401,7 @@ where
405401
type Item = (u8, &'a Miniscript<Pk, Tap>);
406402

407403
fn next(&mut self) -> Option<Self::Item> {
408-
while !self.stack.is_empty() {
409-
let (depth, last) = self.stack.pop().expect("Size checked above");
404+
while let Some((depth, last)) = self.stack.pop() {
410405
match *last {
411406
TapTree::Tree(ref l, ref r) => {
412407
self.stack.push((depth + 1, r));

0 commit comments

Comments
 (0)