From 5b194c268d4fd477b688be76b8921ab2e67f6f36 Mon Sep 17 00:00:00 2001 From: LLFourn Date: Wed, 19 May 2021 16:10:06 +1000 Subject: [PATCH] Fix clippy warnings inside testutils macro Now that it's inside the main repo clippy is having a go at me. --- src/testutils/mod.rs | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/testutils/mod.rs b/src/testutils/mod.rs index 506c53d5..5d7146bd 100644 --- a/src/testutils/mod.rs +++ b/src/testutils/mod.rs @@ -123,20 +123,13 @@ macro_rules! testutils { ( @e $descriptors:expr, $child:expr ) => ({ testutils!(@external $descriptors, $child) }); ( @i $descriptors:expr, $child:expr ) => ({ testutils!(@internal $descriptors, $child) }); - ( @tx ( $( ( $( $addr:tt )* ) => $amount:expr ),+ ) $( ( @locktime $locktime:expr ) )* $( ( @confirmations $confirmations:expr ) )* $( ( @replaceable $replaceable:expr ) )* ) => ({ - let mut outs = Vec::new(); - $( outs.push($crate::testutils::TestIncomingOutput::new($amount, testutils!( $($addr)* ))); )+ - #[allow(unused_mut)] - let mut locktime = None::; - $( locktime = Some($locktime); )* + ( @tx ( $( ( $( $addr:tt )* ) => $amount:expr ),+ ) $( ( @locktime $locktime:expr ) )? $( ( @confirmations $confirmations:expr ) )? $( ( @replaceable $replaceable:expr ) )? ) => ({ + let outs = vec![$( $crate::testutils::TestIncomingOutput::new($amount, testutils!( $($addr)* ))),+]; - #[allow(unused_assignments, unused_mut)] - let mut min_confirmations = None::; - $( min_confirmations = Some($confirmations); )* + let locktime = None::$(.or(Some($locktime)))?; - #[allow(unused_assignments, unused_mut)] - let mut replaceable = None::; - $( replaceable = Some($replaceable); )* + let min_confirmations = None::$(.or(Some($confirmations)))?; + let replaceable = None::$(.or(Some($replaceable)))?; $crate::testutils::TestIncomingTx::new(outs, min_confirmations, locktime, replaceable) }); @@ -156,13 +149,8 @@ macro_rules! testutils { &seed, ); - #[allow(unused_assignments)] - let mut external_path = None::; - $( external_path = Some($external_path.to_string()); )? - - #[allow(unused_assignments)] - let mut internal_path = None::; - $( internal_path = Some($internal_path.to_string()); )? + let external_path = None::$(.or(Some($external_path.to_string())))?; + let internal_path = None::$(.or(Some($internal_path.to_string())))?; (key.unwrap().to_string(), external_path, internal_path) }); @@ -189,7 +177,7 @@ macro_rules! testutils { map }); - ( @descriptors ( $external_descriptor:expr ) $( ( $internal_descriptor:expr ) )* $( ( @keys $( $keys:tt )* ) )* ) => ({ + ( @descriptors ( $external_descriptor:expr ) $( ( $internal_descriptor:expr ) )? $( ( @keys $( $keys:tt )* ) )* ) => ({ use std::str::FromStr; use std::collections::HashMap; use miniscript::descriptor::Descriptor; @@ -218,9 +206,7 @@ macro_rules! testutils { }); let external = external.to_string(); - #[allow(unused_assignments, unused_mut)] - let mut internal = None::; - $( + let internal = None::$(.or({ let string_internal: Descriptor = FromStr::from_str($internal_descriptor).unwrap(); let string_internal: Descriptor = string_internal.translate_pk_infallible::<_, _>(|k| { @@ -236,8 +222,8 @@ macro_rules! testutils { kh.clone() } }); - internal = Some(string_internal.to_string()); - )* + Some(string_internal.to_string()) + }))?; (external, internal) })