Skip to content

Commit 5dcd5fc

Browse files
committed
policy: Remove function local wildcard imports
Remove `use Foo::*` for bringing enum variants into scope.
1 parent 6af27b1 commit 5dcd5fc

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

src/policy/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ impl fmt::Display for LiftError {
8080
#[cfg(feature = "std")]
8181
impl error::Error for LiftError {
8282
fn cause(&self) -> Option<&dyn error::Error> {
83-
use self::LiftError::*;
84-
8583
match self {
86-
HeightTimelockCombination | BranchExceedResourceLimits | RawDescriptorLift => None,
84+
Self::HeightTimelockCombination
85+
| Self::BranchExceedResourceLimits
86+
| Self::RawDescriptorLift => None,
8787
}
8888
}
8989
}

src/policy/semantic.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,11 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
168168

169169
// Helper function to compute the number of constraints in policy.
170170
fn n_terminals(&self) -> usize {
171-
use Policy::*;
172-
173171
let mut n_terminals = vec![];
174172
for data in self.rtl_post_order_iter() {
175173
let num = match data.node {
176-
Thresh(thresh) => (0..thresh.n()).map(|_| n_terminals.pop().unwrap()).sum(),
177-
Trivial | Unsatisfiable => 0,
174+
Self::Thresh(thresh) => (0..thresh.n()).map(|_| n_terminals.pop().unwrap()).sum(),
175+
Self::Trivial | Self::Unsatisfiable => 0,
178176
_leaf => 1,
179177
};
180178
n_terminals.push(num);
@@ -512,19 +510,19 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
512510
/// Filters a policy by eliminating relative timelock constraints
513511
/// that are not satisfied at the given `age`.
514512
pub fn at_age(self, age: relative::LockTime) -> Self {
515-
use Policy::*;
516-
517513
let mut at_age = vec![];
518514
for data in Arc::new(self).rtl_post_order_iter() {
519515
let new_policy = match data.node.as_ref() {
520-
Older(ref t) => {
516+
Self::Older(ref t) => {
521517
if relative::LockTime::from(*t).is_implied_by(age) {
522-
Some(Older(*t))
518+
Some(Self::Older(*t))
523519
} else {
524-
Some(Unsatisfiable)
520+
Some(Self::Unsatisfiable)
525521
}
526522
}
527-
Thresh(ref thresh) => Some(Thresh(thresh.map_ref(|_| at_age.pop().unwrap()))),
523+
Self::Thresh(ref thresh) => {
524+
Some(Self::Thresh(thresh.map_ref(|_| at_age.pop().unwrap())))
525+
}
528526
_ => None,
529527
};
530528
match new_policy {
@@ -542,19 +540,19 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
542540
/// Filters a policy by eliminating absolute timelock constraints
543541
/// that are not satisfied at the given `n` (`n OP_CHECKLOCKTIMEVERIFY`).
544542
pub fn at_lock_time(self, n: absolute::LockTime) -> Self {
545-
use Policy::*;
546-
547543
let mut at_age = vec![];
548544
for data in Arc::new(self).rtl_post_order_iter() {
549545
let new_policy = match data.node.as_ref() {
550-
After(t) => {
546+
Self::After(t) => {
551547
if absolute::LockTime::from(*t).is_implied_by(n) {
552-
Some(After(*t))
548+
Some(Self::After(*t))
553549
} else {
554-
Some(Unsatisfiable)
550+
Some(Self::Unsatisfiable)
555551
}
556552
}
557-
Thresh(ref thresh) => Some(Thresh(thresh.map_ref(|_| at_age.pop().unwrap()))),
553+
Self::Thresh(ref thresh) => {
554+
Some(Self::Thresh(thresh.map_ref(|_| at_age.pop().unwrap())))
555+
}
558556
_ => None,
559557
};
560558
match new_policy {
@@ -584,16 +582,19 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
584582
///
585583
/// Returns `None` if the policy is not satisfiable.
586584
pub fn minimum_n_keys(&self) -> Option<usize> {
587-
use Policy::*;
588-
589585
let mut minimum_n_keys = vec![];
590586
for data in self.rtl_post_order_iter() {
591587
let minimum_n_key = match data.node {
592-
Unsatisfiable => None,
593-
Trivial | After(..) | Older(..) | Sha256(..) | Hash256(..) | Ripemd160(..)
594-
| Hash160(..) => Some(0),
595-
Key(..) => Some(1),
596-
Thresh(ref thresh) => {
588+
Self::Unsatisfiable => None,
589+
Self::Trivial
590+
| Self::After(..)
591+
| Self::Older(..)
592+
| Self::Sha256(..)
593+
| Self::Hash256(..)
594+
| Self::Ripemd160(..)
595+
| Self::Hash160(..) => Some(0),
596+
Self::Key(..) => Some(1),
597+
Self::Thresh(ref thresh) => {
597598
let mut sublens = (0..thresh.n())
598599
.filter_map(|_| minimum_n_keys.pop().unwrap())
599600
.collect::<Vec<usize>>();
@@ -620,15 +621,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
620621
/// in general this appears to require Gröbner basis techniques that are not
621622
/// implemented.
622623
pub fn sorted(self) -> Self {
623-
use Policy::*;
624-
625624
let mut sorted = vec![];
626625
for data in Arc::new(self).rtl_post_order_iter() {
627626
let new_policy = match data.node.as_ref() {
628-
Thresh(ref thresh) => {
627+
Self::Thresh(ref thresh) => {
629628
let mut new_thresh = thresh.map_ref(|_| sorted.pop().unwrap());
630629
new_thresh.data_mut().sort();
631-
Some(Thresh(new_thresh))
630+
Some(Self::Thresh(new_thresh))
632631
}
633632
_ => None,
634633
};

0 commit comments

Comments
 (0)