Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit bcb778f

Browse files
committed
Make linter and clippy as happy as possible while staying compatible to 1.14.0
1 parent 7ff0f3d commit bcb778f

File tree

3 files changed

+29
-48
lines changed

3 files changed

+29
-48
lines changed

src/de.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ mod hrp_sm {
8080
}
8181

8282
fn is_final(&self) -> bool {
83-
if *self == States::ParseL || *self == States::ParseN {
84-
false
85-
} else {
86-
true
87-
}
83+
!(*self == States::ParseL || *self == States::ParseN)
8884
}
8985
}
9086

@@ -710,7 +706,6 @@ mod test {
710706
use de::ParseError;
711707
use secp256k1::{PublicKey, Secp256k1};
712708
use bech32::u5;
713-
use SignedRawInvoice;
714709
use bitcoin_hashes::hex::FromHex;
715710
use bitcoin_hashes::sha256::Sha256Hash;
716711

src/lib.rs

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const MAX_EXPIRY_TIME: u64 = 60 * 60 * 24 * 356;
3737
/// please open an issue. If all tests pass you should be able to use this library safely by just
3838
/// removing this function till we patch it accordingly.
3939
fn __system_time_size_check() {
40-
/// Use 2 * sizeof(u64) as expected size since the expected underlying implementation is storing
41-
/// a `Duration` since `SystemTime::UNIX_EPOCH`.
40+
// Use 2 * sizeof(u64) as expected size since the expected underlying implementation is storing
41+
// a `Duration` since `SystemTime::UNIX_EPOCH`.
4242
unsafe { std::mem::transmute::<SystemTime, [u8; 16]>(UNIX_EPOCH); }
4343
}
4444

@@ -205,11 +205,11 @@ impl SiPrefix {
205205
/// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
206206
/// This is effectively 10^12 * the prefix multiplier
207207
pub fn multiplier(&self) -> u64 {
208-
match self {
209-
&SiPrefix::Milli => 1_000_000_000,
210-
&SiPrefix::Micro => 1_000_000,
211-
&SiPrefix::Nano => 1_000,
212-
&SiPrefix::Pico => 1,
208+
match *self {
209+
SiPrefix::Milli => 1_000_000_000,
210+
SiPrefix::Micro => 1_000_000,
211+
SiPrefix::Nano => 1_000,
212+
SiPrefix::Pico => 1,
213213
}
214214
}
215215

@@ -311,8 +311,6 @@ pub struct RouteHop {
311311
}
312312

313313
pub mod constants {
314-
use bech32::u5;
315-
316314
pub const TAG_PAYMENT_HASH: u8 = 1;
317315
pub const TAG_DESCRIPTION: u8 = 13;
318316
pub const TAG_PAYEE_PUB_KEY: u8 = 19;
@@ -323,17 +321,6 @@ pub mod constants {
323321
pub const TAG_ROUTE: u8 = 3;
324322
}
325323

326-
/// FOR INTERNAL USE ONLY! READ BELOW!
327-
///
328-
/// It's a convenience function to convert `u8` tags to `u5` tags. Therefore `tag` has to
329-
/// be in range `[0..32]`.
330-
///
331-
/// # Panics
332-
/// If the `tag` value is not in the range `[0..32]`.
333-
fn as_u5(tag: u8) -> u5 {
334-
u5::try_from_u8(tag).unwrap()
335-
}
336-
337324
impl InvoiceBuilder<tb::False, tb::False, tb::False> {
338325
/// Construct new, empty `InvoiceBuilder`. All necessary fields have to be filled first before
339326
/// `InvoiceBuilder::build(self)` becomes available.
@@ -597,7 +584,7 @@ impl SignedRawInvoice {
597584
recovered_pub_key = Some(recovered);
598585
}
599586

600-
let pub_key = included_pub_key.or(recovered_pub_key.as_ref())
587+
let pub_key = included_pub_key.or_else(|| recovered_pub_key.as_ref())
601588
.expect("One is always present");
602589

603590
let hash = Message::from_slice(&self.hash[..])
@@ -635,8 +622,8 @@ impl SignedRawInvoice {
635622
/// ```
636623
macro_rules! find_extract {
637624
($iter:expr, $enm:pat, $enm_var:ident) => {
638-
$iter.filter_map(|tf| match tf {
639-
&$enm => Some($enm_var),
625+
$iter.filter_map(|tf| match *tf {
626+
$enm => Some($enm_var),
640627
_ => None,
641628
}).next()
642629
};
@@ -705,8 +692,8 @@ impl RawInvoice {
705692
// function's type signature.
706693
// TODO: refactor once impl Trait is available
707694
fn match_raw(raw: &RawTaggedField) -> Option<&TaggedField> {
708-
match raw {
709-
&RawTaggedField::KnownSemantics(ref tf) => Some(tf),
695+
match *raw {
696+
RawTaggedField::KnownSemantics(ref tf) => Some(tf),
710697
_ => None,
711698
}
712699
}
@@ -741,14 +728,14 @@ impl RawInvoice {
741728
pub fn fallbacks(&self) -> Vec<&Fallback> {
742729
self.known_tagged_fields().filter_map(|tf| match tf {
743730
&TaggedField::Fallback(ref f) => Some(f),
744-
num_traits => None,
731+
_ => None,
745732
}).collect::<Vec<&Fallback>>()
746733
}
747734

748735
pub fn routes(&self) -> Vec<&Route> {
749736
self.known_tagged_fields().filter_map(|tf| match tf {
750737
&TaggedField::Route(ref r) => Some(r),
751-
num_traits => None,
738+
_ => None,
752739
}).collect::<Vec<&Route>>()
753740
}
754741

@@ -819,7 +806,7 @@ impl Deref for PositiveTimestamp {
819806
}
820807

821808
impl Invoice {
822-
fn into_signed_raw(self) -> SignedRawInvoice {
809+
pub fn into_signed_raw(self) -> SignedRawInvoice {
823810
self.signed_invoice
824811
}
825812

@@ -1132,22 +1119,21 @@ mod test {
11321119

11331120
#[test]
11341121
fn test_system_time_bounds_assumptions() {
1135-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
1136-
1137-
/// The upper and lower bounds of `SystemTime` are not part of its public contract and are
1138-
/// platform specific. That's why we have to test if our assumptions regarding these bounds
1139-
/// hold on the target platform.
1140-
///
1141-
/// If this test fails on your platform, please don't use the library and open an issue
1142-
/// instead so we can resolve the situation. Currently this library is tested on:
1143-
/// * Linux (64bit)
1122+
use std::time::{Duration, UNIX_EPOCH};
1123+
1124+
// The upper and lower bounds of `SystemTime` are not part of its public contract and are
1125+
// platform specific. That's why we have to test if our assumptions regarding these bounds
1126+
// hold on the target platform.
1127+
//
1128+
// If this test fails on your platform, please don't use the library and open an issue
1129+
// instead so we can resolve the situation. Currently this library is tested on:
1130+
// * Linux (64bit)
11441131
let _ = UNIX_EPOCH + Duration::from_secs(::std::i64::MAX as u64);
11451132
}
11461133

11471134
#[test]
11481135
fn test_calc_invoice_hash() {
11491136
use ::{RawInvoice, RawHrp, RawDataPart, Currency, PositiveTimestamp};
1150-
use secp256k1::*;
11511137
use ::TaggedField::*;
11521138

11531139
let invoice = RawInvoice {
@@ -1186,7 +1172,7 @@ mod test {
11861172
use {SignedRawInvoice, Signature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
11871173
PositiveTimestamp};
11881174

1189-
let mut invoice = SignedRawInvoice {
1175+
let invoice = SignedRawInvoice {
11901176
raw_invoice: RawInvoice {
11911177
hrp: RawHrp {
11921178
currency: Currency::Bitcoin,

src/ser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl Display for RawHrp {
4646

4747
impl Display for Currency {
4848
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
49-
let currency_code = match self {
50-
&Currency::Bitcoin => "bc",
51-
&Currency::BitcoinTestnet => "tb",
49+
let currency_code = match *self {
50+
Currency::Bitcoin => "bc",
51+
Currency::BitcoinTestnet => "tb",
5252
};
5353
write!(f, "{}", currency_code)
5454
}

0 commit comments

Comments
 (0)