diff --git a/clippy.toml b/clippy.toml index 11d46a73f..7ebfae606 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1,3 @@ msrv = "1.48.0" +# plan API returns Self as an error type for an large-ish enum +large-error-threshold = 256 diff --git a/src/descriptor/checksum.rs b/src/descriptor/checksum.rs index 31060694f..92bfd3055 100644 --- a/src/descriptor/checksum.rs +++ b/src/descriptor/checksum.rs @@ -114,11 +114,11 @@ impl Engine { let mut chars = [0 as char; CHECKSUM_LENGTH]; let mut checksum_remaining = CHECKSUM_LENGTH; - for j in 0..CHECKSUM_LENGTH { + for checksum_ch in &mut chars { checksum_remaining -= 1; let unpacked = self.inner.residue().unpack(checksum_remaining); let fe = Fe32::try_from(unpacked).expect("5 bits fits in an fe32"); - chars[j] = fe.to_char(); + *checksum_ch = fe.to_char(); } chars } diff --git a/src/descriptor/key.rs b/src/descriptor/key.rs index cd4c828e8..f18875cb5 100644 --- a/src/descriptor/key.rs +++ b/src/descriptor/key.rs @@ -589,7 +589,7 @@ impl DescriptorPublicKey { }; xpub.derivation_paths .paths() - .into_iter() + .iter() .map(|p| origin_path.extend(p)) .collect() } @@ -852,8 +852,7 @@ fn parse_xkey_deriv( // step all the vectors of indexes contain a single element. If it did though, one of the // vectors contains more than one element. // Now transform this list of vectors of steps into distinct derivation paths. - .fold(Ok(Vec::new()), |paths, index_list| { - let mut paths = paths?; + .try_fold(Vec::new(), |mut paths, index_list| { let mut index_list = index_list?.into_iter(); let first_index = index_list .next() @@ -940,12 +939,9 @@ impl DescriptorXKey { let (fingerprint, path) = keysource; let (compare_fingerprint, compare_path) = match self.origin { - Some((fingerprint, ref path)) => ( - fingerprint, - path.into_iter() - .chain(self.derivation_path.into_iter()) - .collect(), - ), + Some((fingerprint, ref path)) => { + (fingerprint, path.into_iter().chain(&self.derivation_path).collect()) + } None => ( self.xkey.xkey_fingerprint(secp), self.derivation_path.into_iter().collect::>(), diff --git a/src/descriptor/tr.rs b/src/descriptor/tr.rs index 81cb5c65a..e4815d657 100644 --- a/src/descriptor/tr.rs +++ b/src/descriptor/tr.rs @@ -90,13 +90,7 @@ impl PartialEq for Tr { impl Eq for Tr {} impl PartialOrd for Tr { - fn partial_cmp(&self, other: &Self) -> Option { - match self.internal_key.partial_cmp(&other.internal_key) { - Some(cmp::Ordering::Equal) => {} - ord => return ord, - } - self.tree.partial_cmp(&other.tree) - } + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for Tr { @@ -737,7 +731,7 @@ where wit.push(Placeholder::TapScript(leaf_script.0)); wit.push(Placeholder::TapControlBlock(control_block)); - let wit_size = witness_size(&wit); + let wit_size = witness_size(wit); if min_wit_len.is_some() && Some(wit_size) > min_wit_len { continue; } else { diff --git a/src/iter/mod.rs b/src/iter/mod.rs index f8dbed939..553ae0f47 100644 --- a/src/iter/mod.rs +++ b/src/iter/mod.rs @@ -82,7 +82,7 @@ impl<'a, Pk: MiniscriptKey> TreeLike for &'a policy::Concrete { } } -impl<'a, Pk: MiniscriptKey> TreeLike for Arc> { +impl TreeLike for Arc> { fn as_node(&self) -> Tree { use policy::Concrete::*; match self.as_ref() { diff --git a/src/lib.rs b/src/lib.rs index 225d97df2..83119a764 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,6 +85,8 @@ #![deny(dead_code)] #![deny(unused_imports)] #![deny(missing_docs)] +// Clippy lints that we have disabled +#![allow(clippy::iter_kv_map)] // https://github.com/rust-lang/rust-clippy/issues/11752 #[cfg(target_pointer_width = "16")] compile_error!( @@ -116,7 +118,6 @@ mod macros; mod pub_macros; use internals::hex::exts::DisplayHex; -pub use pub_macros::*; pub mod descriptor; pub mod expression; @@ -812,6 +813,7 @@ mod tests { } } +#[allow(unused_imports)] // this is an internal prelude module; not all imports are used with every feature combination mod prelude { // Mutex implementation from LDK // https://github.com/lightningdevkit/rust-lightning/blob/9bdce47f0e0516e37c89c09f1975dfc06b5870b1/lightning-invoice/src/sync.rs diff --git a/src/miniscript/types/extra_props.rs b/src/miniscript/types/extra_props.rs index d527caea6..8cbb4aa3c 100644 --- a/src/miniscript/types/extra_props.rs +++ b/src/miniscript/types/extra_props.rs @@ -792,11 +792,11 @@ impl Property for ExtData { .iter() .rev() .enumerate() - .fold(Some(0), |acc, (i, &(x, y))| { + .try_fold(0, |acc, (i, &(x, y))| { if i <= k { - opt_add(acc, x) + x.map(|x| acc + x) } else { - opt_add(acc, y) + y.map(|y| acc + y) } }); @@ -805,11 +805,11 @@ impl Property for ExtData { .iter() .rev() .enumerate() - .fold(Some(0), |acc, (i, &(x, y))| { + .try_fold(0, |acc, (i, &(x, y))| { if i <= k { - opt_max(acc, x) + x.map(|x| acc + x) } else { - opt_max(acc, y) + y.map(|y| acc + y) } }); @@ -819,26 +819,25 @@ impl Property for ExtData { max_sat_size_vec .iter() .enumerate() - .fold(Some((0, 0)), |acc, (i, &(x, y))| { + .try_fold((0, 0), |acc, (i, &(x, y))| { if i <= k { - opt_tuple_add(acc, x) + x.map(|(x0, x1)| (acc.0 + x0, acc.1 + x1)) } else { - opt_tuple_add(acc, y) + y.map(|(y0, y1)| (acc.0 + y0, acc.1 + y1)) } }); ops_count_sat_vec.sort_by(sat_minus_dissat); - let op_count_sat = - ops_count_sat_vec - .iter() - .enumerate() - .fold(Some(0), |acc, (i, &(x, y))| { - if i <= k { - opt_add(acc, x) - } else { - opt_add(acc, Some(y)) - } - }); + let op_count_sat = ops_count_sat_vec + .iter() + .enumerate() + .try_fold(0, |acc, (i, &(x, y))| { + if i <= k { + x.map(|x| acc + x) + } else { + Some(acc + y) + } + }); Ok(ExtData { pk_cost: pk_cost + n - 1, //all pk cost + (n-1)*ADD @@ -1049,11 +1048,6 @@ fn opt_max(a: Option, b: Option) -> Option { /// Returns Some(x+y) is both x and y are Some. Otherwise, returns `None`. fn opt_add(a: Option, b: Option) -> Option { a.and_then(|x| b.map(|y| x + y)) } -/// Returns Some((x0+y0, x1+y1)) is both x and y are Some. Otherwise, returns `None`. -fn opt_tuple_add(a: Option<(usize, usize)>, b: Option<(usize, usize)>) -> Option<(usize, usize)> { - a.and_then(|x| b.map(|(w, s)| (w + x.0, s + x.1))) -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/plan.rs b/src/plan.rs index 32e9aa75d..3383643ce 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -255,13 +255,13 @@ impl Plan { // scriptSig len (1) + OP_0 (1) + OP_PUSHBYTES_32 (1) +