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

Commit 6e7fa21

Browse files
committed
Make linter and clippy as happy as possible while staying compatible to 1.14.0
1 parent 84cfec7 commit 6e7fa21

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
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: 16 additions & 30 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

@@ -246,11 +246,11 @@ impl SiPrefix {
246246
/// Returns the multiplier to go from a BTC value to picoBTC implied by this SiPrefix.
247247
/// This is effectively 10^12 * the prefix multiplier
248248
pub fn multiplier(&self) -> u64 {
249-
match self {
250-
&SiPrefix::Milli => 1_000_000_000,
251-
&SiPrefix::Micro => 1_000_000,
252-
&SiPrefix::Nano => 1_000,
253-
&SiPrefix::Pico => 1,
249+
match *self {
250+
SiPrefix::Milli => 1_000_000_000,
251+
SiPrefix::Micro => 1_000_000,
252+
SiPrefix::Nano => 1_000,
253+
SiPrefix::Pico => 1,
254254
}
255255
}
256256

@@ -354,8 +354,6 @@ pub struct RouteHop {
354354
}
355355

356356
pub mod constants {
357-
use bech32::u5;
358-
359357
pub const TAG_PAYMENT_HASH: u8 = 1;
360358
pub const TAG_DESCRIPTION: u8 = 13;
361359
pub const TAG_PAYEE_PUB_KEY: u8 = 19;
@@ -366,17 +364,6 @@ pub mod constants {
366364
pub const TAG_ROUTE: u8 = 3;
367365
}
368366

369-
/// FOR INTERNAL USE ONLY! READ BELOW!
370-
///
371-
/// It's a convenience function to convert `u8` tags to `u5` tags. Therefore `tag` has to
372-
/// be in range `[0..32]`.
373-
///
374-
/// # Panics
375-
/// If the `tag` value is not in the range `[0..32]`.
376-
fn as_u5(tag: u8) -> u5 {
377-
u5::try_from_u8(tag).unwrap()
378-
}
379-
380367
impl InvoiceBuilder<tb::False, tb::False, tb::False> {
381368
/// Construct new, empty `InvoiceBuilder`. All necessary fields have to be filled first before
382369
/// `InvoiceBuilder::build(self)` becomes available.
@@ -633,7 +620,7 @@ impl SignedRawInvoice {
633620
recovered_pub_key = Some(recovered);
634621
}
635622

636-
let pub_key = included_pub_key.or(recovered_pub_key.as_ref())
623+
let pub_key = included_pub_key.or_else(|| recovered_pub_key.as_ref())
637624
.expect("One is always present");
638625

639626
let hash = Message::from_slice(&self.hash[..])
@@ -671,8 +658,8 @@ impl SignedRawInvoice {
671658
/// ```
672659
macro_rules! find_extract {
673660
($iter:expr, $enm:pat, $enm_var:ident) => {
674-
$iter.filter_map(|tf| match tf {
675-
&$enm => Some($enm_var),
661+
$iter.filter_map(|tf| match *tf {
662+
$enm => Some($enm_var),
676663
_ => None,
677664
}).next()
678665
};
@@ -741,8 +728,8 @@ impl RawInvoice {
741728
// function's type signature.
742729
// TODO: refactor once impl Trait is available
743730
fn match_raw(raw: &RawTaggedField) -> Option<&TaggedField> {
744-
match raw {
745-
&RawTaggedField::KnownSemantics(ref tf) => Some(tf),
731+
match *raw {
732+
RawTaggedField::KnownSemantics(ref tf) => Some(tf),
746733
_ => None,
747734
}
748735
}
@@ -777,14 +764,14 @@ impl RawInvoice {
777764
pub fn fallbacks(&self) -> Vec<&Fallback> {
778765
self.known_tagged_fields().filter_map(|tf| match tf {
779766
&TaggedField::Fallback(ref f) => Some(f),
780-
num_traits => None,
767+
_ => None,
781768
}).collect::<Vec<&Fallback>>()
782769
}
783770

784771
pub fn routes(&self) -> Vec<&Route> {
785772
self.known_tagged_fields().filter_map(|tf| match tf {
786773
&TaggedField::Route(ref r) => Some(r),
787-
num_traits => None,
774+
_ => None,
788775
}).collect::<Vec<&Route>>()
789776
}
790777

@@ -854,7 +841,7 @@ impl Deref for PositiveTimestamp {
854841
}
855842

856843
impl Invoice {
857-
fn into_signed_raw(self) -> SignedRawInvoice {
844+
pub fn into_signed_raw(self) -> SignedRawInvoice {
858845
self.signed_invoice
859846
}
860847

@@ -1183,7 +1170,6 @@ mod test {
11831170
#[test]
11841171
fn test_calc_invoice_hash() {
11851172
use ::{RawInvoice, RawHrp, RawDataPart, Currency, PositiveTimestamp};
1186-
use secp256k1::*;
11871173
use ::TaggedField::*;
11881174

11891175
let invoice = RawInvoice {
@@ -1222,7 +1208,7 @@ mod test {
12221208
use {SignedRawInvoice, Signature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
12231209
PositiveTimestamp};
12241210

1225-
let mut invoice = SignedRawInvoice {
1211+
let invoice = SignedRawInvoice {
12261212
raw_invoice: RawInvoice {
12271213
hrp: RawHrp {
12281214
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)