Skip to content

Commit d8c397d

Browse files
committed
Fix some macro bugs for 1.41.1
1 parent ffe3668 commit d8c397d

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

src/descriptor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ impl Descriptor<DescriptorPublicKey> {
653653

654654
impl_from_tree!(
655655
Descriptor<Pk>,
656-
/// Parse an expression tree into a descriptor
656+
/// Parse an expression tree into a descriptor.
657657
fn from_tree(top: &expression::Tree) -> Result<Descriptor<Pk>, Error> {
658658
Ok(match (top.name, top.args.len() as u32) {
659659
("pkh", 1) => Descriptor::Pkh(Pkh::from_tree(top)?),

src/descriptor/tr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,11 @@ where
388388
}
389389
}
390390

391+
#[rustfmt::skip]
391392
impl_block_str!(
392393
Tr<Pk>,
393394
// Helper function to parse taproot script path
394-
fn parse_tr_script_spend(tree: &expression::Tree) -> Result<TapTree<Pk>, Error> {
395+
fn parse_tr_script_spend(tree: &expression::Tree,) -> Result<TapTree<Pk>, Error> {
395396
match tree {
396397
expression::Tree { name, args } if !name.is_empty() && args.is_empty() => {
397398
let script = Miniscript::<Pk, Tap>::from_str(name)?;

src/macros.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ macro_rules! policy_str {
1919
/// Macro for implementing FromTree trait. This avoids copying all the Pk::Associated type bounds
2020
/// throughout the codebase.
2121
macro_rules! impl_from_tree {
22-
($(;$gen:ident; $gen_con:ident, )* $name: ty, $fn: item) => {
22+
($(;$gen:ident; $gen_con:ident, )* $name: ty,
23+
$(#[$meta:meta])*
24+
fn $fn:ident ( $($arg:ident : $type:ty),* ) -> $ret:ty
25+
$body:block
26+
) => {
2327
impl<Pk $(, $gen)*> $crate::expression::FromTree for $name
2428
where
2529
Pk: MiniscriptKey + core::str::FromStr,
@@ -28,15 +32,24 @@ macro_rules! impl_from_tree {
2832
<<Pk as MiniscriptKey>::Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
2933
$($gen : $gen_con,)*
3034
{
31-
$fn
35+
36+
$(#[$meta])*
37+
fn $fn($($arg: $type)* ) -> $ret {
38+
$body
39+
}
3240
}
3341
};
3442
}
3543

3644
/// Macro for implementing FromTree trait. This avoids copying all the Pk::Associated type bounds
3745
/// throughout the codebase.
3846
macro_rules! impl_from_str {
39-
($(;$gen:ident; $gen_con:ident, )* $name: ty $(, $it: item)*) => {
47+
($(;$gen:ident; $gen_con:ident, )* $name: ty,
48+
type Err = $err_ty:ty;,
49+
$(#[$meta:meta])*
50+
fn $fn:ident ( $($arg:ident : $type:ty),* ) -> $ret:ty
51+
$body:block
52+
) => {
4053
impl<Pk $(, $gen)*> core::str::FromStr for $name
4154
where
4255
Pk: MiniscriptKey + core::str::FromStr,
@@ -45,15 +58,24 @@ macro_rules! impl_from_str {
4558
<<Pk as MiniscriptKey>::Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
4659
$($gen : $gen_con,)*
4760
{
48-
$($it)*
61+
type Err = $err_ty;
62+
63+
$(#[$meta])*
64+
fn $fn($($arg: $type)* ) -> $ret {
65+
$body
66+
}
4967
}
5068
};
5169
}
5270

5371
/// Macro for implementing FromTree trait. This avoids copying all the Pk::Associated type bounds
5472
/// throughout the codebase.
5573
macro_rules! impl_block_str {
56-
($(;$gen:ident; $gen_con:ident, )* $name: ty $(, $it: item)*) => {
74+
($(;$gen:ident; $gen_con:ident, )* $name: ty,
75+
$(#[$meta:meta])*
76+
$v:vis fn $fn:ident ( $($arg:ident : $type:ty, )* ) -> $ret:ty
77+
$body:block
78+
) => {
5779
impl<Pk $(, $gen)*> $name
5880
where
5981
Pk: MiniscriptKey + std::str::FromStr,
@@ -62,7 +84,10 @@ macro_rules! impl_block_str {
6284
<<Pk as MiniscriptKey>::Hash as std::str::FromStr>::Err: std::string::ToString,
6385
$($gen : $gen_con,)*
6486
{
65-
$($it)*
87+
$(#[$meta])*
88+
$v fn $fn($($arg: $type,)* ) -> $ret {
89+
$body
90+
}
6691
}
6792
};
6893
}

src/miniscript/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl_block_str!(
350350
/// Some of the analysis guarantees of miniscript are lost when dealing with
351351
/// insane scripts. In general, in a multi-party setting users should only
352352
/// accept sane scripts.
353-
pub fn from_str_insane(s: &str) -> Result<Miniscript<Pk, Ctx>, Error>
353+
pub fn from_str_insane(s: &str,) -> Result<Miniscript<Pk, Ctx>, Error>
354354
{
355355
// This checks for invalid ASCII chars
356356
let top = expression::Tree::from_str(s)?;

src/policy/concrete.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,14 +698,14 @@ impl_from_str!(
698698

699699
serde_string_impl_pk!(Policy, "a miniscript concrete policy");
700700

701+
#[rustfmt::skip]
701702
impl_block_str!(
702703
Policy<Pk>,
703704
/// Helper function for `from_tree` to parse subexpressions with
704705
/// names of the form x@y
705-
fn from_tree_prob(
706-
top: &expression::Tree,
707-
allow_prob: bool,
708-
) -> Result<(usize, Policy<Pk>), Error> {
706+
fn from_tree_prob(top: &expression::Tree, allow_prob: bool,)
707+
-> Result<(usize, Policy<Pk>), Error>
708+
{
709709
let frag_prob;
710710
let frag_name;
711711
let mut name_split = top.name.split('@');

0 commit comments

Comments
 (0)