Skip to content

Commit b601439

Browse files
committed
policy: Remove function local wildcard imports
Remove `use Foo::*` for bringing enum variants into scope.
1 parent 52a5003 commit b601439

2 files changed

Lines changed: 18 additions & 30 deletions

File tree

src/policy/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ 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 | Self::BranchExceedResourceLimits | Self::RawDescriptorLift => None,
8785
}
8886
}
8987
}

src/policy/semantic.rs

Lines changed: 17 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,17 @@ 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) => Some(Self::Thresh(thresh.map_ref(|_| at_age.pop().unwrap()))),
528524
_ => None,
529525
};
530526
match new_policy {
@@ -542,19 +538,17 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
542538
/// Filters a policy by eliminating absolute timelock constraints
543539
/// that are not satisfied at the given `n` (`n OP_CHECKLOCKTIMEVERIFY`).
544540
pub fn at_lock_time(self, n: absolute::LockTime) -> Self {
545-
use Policy::*;
546-
547541
let mut at_age = vec![];
548542
for data in Arc::new(self).rtl_post_order_iter() {
549543
let new_policy = match data.node.as_ref() {
550-
After(t) => {
544+
Self::After(t) => {
551545
if absolute::LockTime::from(*t).is_implied_by(n) {
552-
Some(After(*t))
546+
Some(Self::After(*t))
553547
} else {
554-
Some(Unsatisfiable)
548+
Some(Self::Unsatisfiable)
555549
}
556550
}
557-
Thresh(ref thresh) => Some(Thresh(thresh.map_ref(|_| at_age.pop().unwrap()))),
551+
Self::Thresh(ref thresh) => Some(Self::Thresh(thresh.map_ref(|_| at_age.pop().unwrap()))),
558552
_ => None,
559553
};
560554
match new_policy {
@@ -584,16 +578,14 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
584578
///
585579
/// Returns `None` if the policy is not satisfiable.
586580
pub fn minimum_n_keys(&self) -> Option<usize> {
587-
use Policy::*;
588-
589581
let mut minimum_n_keys = vec![];
590582
for data in self.rtl_post_order_iter() {
591583
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) => {
584+
Self::Unsatisfiable => None,
585+
Self::Trivial | Self::After(..) | Self::Older(..) | Self::Sha256(..) | Self::Hash256(..) | Self::Ripemd160(..)
586+
| Self::Hash160(..) => Some(0),
587+
Self::Key(..) => Some(1),
588+
Self::Thresh(ref thresh) => {
597589
let mut sublens = (0..thresh.n())
598590
.filter_map(|_| minimum_n_keys.pop().unwrap())
599591
.collect::<Vec<usize>>();
@@ -620,15 +612,13 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
620612
/// in general this appears to require Gröbner basis techniques that are not
621613
/// implemented.
622614
pub fn sorted(self) -> Self {
623-
use Policy::*;
624-
625615
let mut sorted = vec![];
626616
for data in Arc::new(self).rtl_post_order_iter() {
627617
let new_policy = match data.node.as_ref() {
628-
Thresh(ref thresh) => {
618+
Self::Thresh(ref thresh) => {
629619
let mut new_thresh = thresh.map_ref(|_| sorted.pop().unwrap());
630620
new_thresh.data_mut().sort();
631-
Some(Thresh(new_thresh))
621+
Some(Self::Thresh(new_thresh))
632622
}
633623
_ => None,
634624
};

0 commit comments

Comments
 (0)