Skip to content

Commit 3ec3d23

Browse files
committed
fix: latest nightly compilers fail to compile w/ infinite recursion
* This fix is backported from latest `miniscript` v0.10.0 release. * See <rust-bitcoin#546> for original PR with fix.
1 parent 424a57a commit 3ec3d23

File tree

10 files changed

+33
-58
lines changed

10 files changed

+33
-58
lines changed

src/descriptor/bare.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ impl_from_str!(
165165
);
166166

167167
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Bare<Pk> {
168-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
169-
where
170-
Pk: 'a,
171-
{
168+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool {
172169
self.ms.for_each_key(pred)
173170
}
174171
}
@@ -327,10 +324,7 @@ impl_from_str!(
327324
);
328325

329326
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Pkh<Pk> {
330-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
331-
where
332-
Pk: 'a,
333-
{
327+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
334328
pred(&self.pk)
335329
}
336330
}

src/descriptor/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,7 @@ where
495495
}
496496

497497
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Descriptor<Pk> {
498-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
499-
where
500-
Pk: 'a,
501-
{
498+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool {
502499
match *self {
503500
Descriptor::Bare(ref bare) => bare.for_each_key(pred),
504501
Descriptor::Pkh(ref pkh) => pkh.for_each_key(pred),

src/descriptor/segwitv0.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,7 @@ impl_from_str!(
248248
);
249249

250250
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Wsh<Pk> {
251-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
252-
where
253-
Pk: 'a,
254-
{
251+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool {
255252
match self.inner {
256253
WshInner::SortedMulti(ref smv) => smv.for_each_key(pred),
257254
WshInner::Ms(ref ms) => ms.for_each_key(pred),

src/descriptor/sh.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
378378
}
379379

380380
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Sh<Pk> {
381-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool
382-
where
383-
Pk: 'a,
384-
{
381+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool {
385382
match self.inner {
386383
ShInner::Wsh(ref wsh) => wsh.for_each_key(pred),
387384
ShInner::SortedMulti(ref smv) => smv.for_each_key(pred),

src/descriptor/sortedmulti.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> SortedMultiVec<Pk, Ctx> {
112112
}
113113

114114
impl<Pk: MiniscriptKey, Ctx: ScriptContext> ForEachKey<Pk> for SortedMultiVec<Pk, Ctx> {
115-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
116-
where
117-
Pk: 'a,
118-
{
115+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
119116
self.pks.iter().all(|key| pred(key))
120117
}
121118
}

src/descriptor/tr.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,7 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Tr<Pk> {
563563
}
564564

565565
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Tr<Pk> {
566-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
567-
where
568-
Pk: 'a,
569-
{
566+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
570567
let script_keys_res = self
571568
.iter_scripts()
572569
.all(|(_d, ms)| ms.for_each_key(&mut pred));

src/miniscript/astelem.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ where
7676
}
7777

7878
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
79-
pub(super) fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool
80-
where
81-
Pk: 'a,
82-
{
79+
pub(super) fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool {
8380
match *self {
8481
Terminal::PkK(ref p) => pred(p),
8582
Terminal::PkH(ref p) => pred(p),
@@ -196,10 +193,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
196193
}
197194

198195
impl<Pk: MiniscriptKey, Ctx: ScriptContext> ForEachKey<Pk> for Terminal<Pk, Ctx> {
199-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
200-
where
201-
Pk: 'a,
202-
{
196+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
203197
self.real_for_each_key(&mut pred)
204198
}
205199
}

src/miniscript/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
285285
}
286286

287287
impl<Pk: MiniscriptKey, Ctx: ScriptContext> ForEachKey<Pk> for Miniscript<Pk, Ctx> {
288-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
289-
where
290-
Pk: 'a,
291-
{
288+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
292289
self.real_for_each_key(&mut pred)
293290
}
294291
}
@@ -312,10 +309,7 @@ where
312309
}
313310

314311
impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx> {
315-
fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool
316-
where
317-
Pk: 'a,
318-
{
312+
fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool {
319313
self.node.real_for_each_key(pred)
320314
}
321315

src/policy/concrete.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,13 @@ impl<Pk: MiniscriptKey> PolicyArc<Pk> {
653653
}
654654

655655
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
656-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
657-
where
658-
Pk: 'a,
659-
{
656+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
657+
self.real_for_each_key(&mut pred)
658+
}
659+
}
660+
661+
impl<Pk: MiniscriptKey> Policy<Pk> {
662+
fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool {
660663
match *self {
661664
Policy::Unsatisfiable | Policy::Trivial => true,
662665
Policy::Key(ref pk) => pred(pk),
@@ -667,9 +670,11 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
667670
| Policy::After(..)
668671
| Policy::Older(..) => true,
669672
Policy::Threshold(_, ref subs) | Policy::And(ref subs) => {
670-
subs.iter().all(|sub| sub.for_each_key(&mut pred))
673+
subs.iter().all(|sub| sub.real_for_each_key(&mut *pred))
671674
}
672-
Policy::Or(ref subs) => subs.iter().all(|(_, sub)| sub.for_each_key(&mut pred)),
675+
Policy::Or(ref subs) => subs
676+
.iter()
677+
.all(|(_, sub)| sub.real_for_each_key(&mut *pred)),
673678
}
674679
}
675680
}

src/policy/semantic.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,28 @@ where
7272
}
7373

7474
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
75-
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool
76-
where
77-
Pk: 'a,
78-
{
75+
fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, mut pred: F) -> bool {
76+
self.real_for_each_key(&mut pred)
77+
}
78+
}
79+
80+
impl<Pk: MiniscriptKey> Policy<Pk> {
81+
fn real_for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: &mut F) -> bool {
7982
match *self {
8083
Policy::Unsatisfiable | Policy::Trivial => true,
81-
Policy::Key(ref _pkh) => todo!("Semantic Policy KeyHash must store Pk"),
84+
Policy::Key(ref pk) => pred(pk),
8285
Policy::Sha256(..)
8386
| Policy::Hash256(..)
8487
| Policy::Ripemd160(..)
8588
| Policy::Hash160(..)
8689
| Policy::After(..)
8790
| Policy::Older(..) => true,
88-
Policy::Threshold(_, ref subs) => subs.iter().all(|sub| sub.for_each_key(&mut pred)),
91+
Policy::Threshold(_, ref subs) => {
92+
subs.iter().all(|sub| sub.real_for_each_key(&mut *pred))
93+
}
8994
}
9095
}
91-
}
9296

93-
impl<Pk: MiniscriptKey> Policy<Pk> {
9497
/// Convert a policy using one kind of public key to another
9598
/// type of public key
9699
///

0 commit comments

Comments
 (0)