Skip to content

Commit 397b38e

Browse files
committed
Fix some macro bugs for 1.41.1
1 parent 197365c commit 397b38e

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
@@ -716,7 +716,7 @@ impl Descriptor<DescriptorPublicKey> {
716716

717717
impl_from_tree!(
718718
Descriptor<Pk>,
719-
/// Parse an expression tree into a descriptor
719+
/// Parse an expression tree into a descriptor.
720720
fn from_tree(top: &expression::Tree) -> Result<Descriptor<Pk>, Error> {
721721
Ok(match (top.name, top.args.len() as u32) {
722722
("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
@@ -384,10 +384,11 @@ where
384384
}
385385
}
386386

387+
#[rustfmt::skip]
387388
impl_block_str!(
388389
Tr<Pk>,
389390
// Helper function to parse taproot script path
390-
fn parse_tr_script_spend(tree: &expression::Tree) -> Result<TapTree<Pk>, Error> {
391+
fn parse_tr_script_spend(tree: &expression::Tree,) -> Result<TapTree<Pk>, Error> {
391392
match tree {
392393
expression::Tree { name, args } if !name.is_empty() && args.is_empty() => {
393394
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,
@@ -30,15 +34,24 @@ macro_rules! impl_from_tree {
3034
<<Pk as MiniscriptKey>::Sha256Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
3135
$($gen : $gen_con,)*
3236
{
33-
$fn
37+
38+
$(#[$meta])*
39+
fn $fn($($arg: $type)* ) -> $ret {
40+
$body
41+
}
3442
}
3543
};
3644
}
3745

3846
/// Macro for implementing FromTree trait. This avoids copying all the Pk::Associated type bounds
3947
/// throughout the codebase.
4048
macro_rules! impl_from_str {
41-
($(;$gen:ident; $gen_con:ident, )* $name: ty $(, $it: item)*) => {
49+
($(;$gen:ident; $gen_con:ident, )* $name: ty,
50+
type Err = $err_ty:ty;,
51+
$(#[$meta:meta])*
52+
fn $fn:ident ( $($arg:ident : $type:ty),* ) -> $ret:ty
53+
$body:block
54+
) => {
4255
impl<Pk $(, $gen)*> core::str::FromStr for $name
4356
where
4457
Pk: MiniscriptKey + core::str::FromStr,
@@ -49,15 +62,24 @@ macro_rules! impl_from_str {
4962
<<Pk as MiniscriptKey>::Sha256Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
5063
$($gen : $gen_con,)*
5164
{
52-
$($it)*
65+
type Err = $err_ty;
66+
67+
$(#[$meta])*
68+
fn $fn($($arg: $type)* ) -> $ret {
69+
$body
70+
}
5371
}
5472
};
5573
}
5674

5775
/// Macro for implementing FromTree trait. This avoids copying all the Pk::Associated type bounds
5876
/// throughout the codebase.
5977
macro_rules! impl_block_str {
60-
($(;$gen:ident; $gen_con:ident, )* $name: ty $(, $it: item)*) => {
78+
($(;$gen:ident; $gen_con:ident, )* $name: ty,
79+
$(#[$meta:meta])*
80+
$v:vis fn $fn:ident ( $($arg:ident : $type:ty, )* ) -> $ret:ty
81+
$body:block
82+
) => {
6183
impl<Pk $(, $gen)*> $name
6284
where
6385
Pk: MiniscriptKey + core::str::FromStr,
@@ -68,7 +90,10 @@ macro_rules! impl_block_str {
6890
<<Pk as MiniscriptKey>::Sha256Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
6991
$($gen : $gen_con,)*
7092
{
71-
$($it)*
93+
$(#[$meta])*
94+
$v fn $fn($($arg: $type,)* ) -> $ret {
95+
$body
96+
}
7297
}
7398
};
7499
}

src/miniscript/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl_block_str!(
339339
/// Some of the analysis guarantees of miniscript are lost when dealing with
340340
/// insane scripts. In general, in a multi-party setting users should only
341341
/// accept sane scripts.
342-
pub fn from_str_insane(s: &str) -> Result<Miniscript<Pk, Ctx>, Error>
342+
pub fn from_str_insane(s: &str,) -> Result<Miniscript<Pk, Ctx>, Error>
343343
{
344344
// This checks for invalid ASCII chars
345345
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
@@ -726,14 +726,14 @@ impl_from_str!(
726726

727727
serde_string_impl_pk!(Policy, "a miniscript concrete policy");
728728

729+
#[rustfmt::skip]
729730
impl_block_str!(
730731
Policy<Pk>,
731732
/// Helper function for `from_tree` to parse subexpressions with
732733
/// names of the form x@y
733-
fn from_tree_prob(
734-
top: &expression::Tree,
735-
allow_prob: bool,
736-
) -> Result<(usize, Policy<Pk>), Error> {
734+
fn from_tree_prob(top: &expression::Tree, allow_prob: bool,)
735+
-> Result<(usize, Policy<Pk>), Error>
736+
{
737737
let frag_prob;
738738
let frag_name;
739739
let mut name_split = top.name.split('@');

0 commit comments

Comments
 (0)