Skip to content

Commit ccac926

Browse files
authored
Merge pull request #2049 from douglaz/run-clippy-fix
Run clippy fix
2 parents 7b2537b + 57017df commit ccac926

File tree

14 files changed

+118
-123
lines changed

14 files changed

+118
-123
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ mod tests {
757757

758758
impl Persister {
759759
fn new(data_dir: String) -> Self {
760-
let filesystem_persister = FilesystemPersister::new(data_dir.clone());
760+
let filesystem_persister = FilesystemPersister::new(data_dir);
761761
Self { graph_error: None, graph_persistence_notifier: None, manager_error: None, scorer_error: None, filesystem_persister }
762762
}
763763

@@ -824,7 +824,7 @@ mod tests {
824824
}
825825

826826
fn expect(&mut self, expectation: TestResult) {
827-
self.event_expectations.get_or_insert_with(|| VecDeque::new()).push_back(expectation);
827+
self.event_expectations.get_or_insert_with(VecDeque::new).push_back(expectation);
828828
}
829829
}
830830

@@ -1226,7 +1226,7 @@ mod tests {
12261226
// Set up a background event handler for SpendableOutputs events.
12271227
let (sender, receiver) = std::sync::mpsc::sync_channel(1);
12281228
let event_handler = move |event: Event| match event {
1229-
Event::SpendableOutputs { .. } => sender.send(event.clone()).unwrap(),
1229+
Event::SpendableOutputs { .. } => sender.send(event).unwrap(),
12301230
Event::ChannelReady { .. } => {},
12311231
Event::ChannelClosed { .. } => {},
12321232
_ => panic!("Unexpected event: {:?}", event),
@@ -1274,7 +1274,7 @@ mod tests {
12741274
let nodes = create_nodes(2, "test_not_pruning_network_graph_until_graph_sync_completion".to_string());
12751275
let data_dir = nodes[0].persister.get_data_dir();
12761276
let (sender, receiver) = std::sync::mpsc::sync_channel(1);
1277-
let persister = Arc::new(Persister::new(data_dir.clone()).with_graph_persistence_notifier(sender));
1277+
let persister = Arc::new(Persister::new(data_dir).with_graph_persistence_notifier(sender));
12781278
let network_graph = nodes[0].network_graph.clone();
12791279
let features = ChannelFeatures::empty();
12801280
network_graph.add_channel_from_partial_announcement(42, 53, features, nodes[0].node.get_our_node_id(), nodes[1].node.get_our_node_id())
@@ -1317,7 +1317,7 @@ mod tests {
13171317
// this should have added two channels
13181318
assert_eq!(network_graph.read_only().channels().len(), 3);
13191319

1320-
let _ = receiver
1320+
receiver
13211321
.recv_timeout(Duration::from_secs(super::FIRST_NETWORK_PRUNE_TIMER * 5))
13221322
.expect("Network graph not pruned within deadline");
13231323

@@ -1344,7 +1344,7 @@ mod tests {
13441344

13451345
let nodes = create_nodes(1, "test_payment_path_scoring".to_string());
13461346
let data_dir = nodes[0].persister.get_data_dir();
1347-
let persister = Arc::new(Persister::new(data_dir.clone()));
1347+
let persister = Arc::new(Persister::new(data_dir));
13481348
let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].no_gossip_sync(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()));
13491349

13501350
let scored_scid = 4242;
@@ -1431,7 +1431,7 @@ mod tests {
14311431
nodes[0].node.push_pending_event(Event::ProbeFailed {
14321432
payment_id: PaymentId([42; 32]),
14331433
payment_hash: PaymentHash([42; 32]),
1434-
path: path.clone(),
1434+
path,
14351435
short_channel_id: Some(scored_scid),
14361436
});
14371437
let event = receiver

lightning-block-sync/src/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub async fn synchronize_listeners<B: Deref + Sized + Send + Sync, C: Cache, L:
181181
let chain_listener = &ChainListenerSet(chain_listeners_at_height);
182182
let mut chain_notifier = ChainNotifier { header_cache, chain_listener };
183183
chain_notifier.connect_blocks(common_ancestor, most_connected_blocks, &mut chain_poller)
184-
.await.or_else(|(e, _)| Err(e))?;
184+
.await.map_err(|(e, _)| e)?;
185185
}
186186

187187
Ok(best_header)

lightning-block-sync/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,15 @@ impl<'a, C: Cache, L: Deref> ChainNotifier<'a, C, L> where L::Target: chain::Lis
414414
let height = header.height;
415415
let block_data = chain_poller
416416
.fetch_block(&header).await
417-
.or_else(|e| Err((e, Some(new_tip))))?;
417+
.map_err(|e| (e, Some(new_tip)))?;
418418
debug_assert_eq!(block_data.block_hash, header.block_hash);
419419

420420
match block_data.deref() {
421421
BlockData::FullBlock(block) => {
422-
self.chain_listener.block_connected(&block, height);
422+
self.chain_listener.block_connected(block, height);
423423
},
424424
BlockData::HeaderOnly(header) => {
425-
self.chain_listener.filtered_block_connected(&header, &[], height);
425+
self.chain_listener.filtered_block_connected(header, &[], height);
426426
},
427427
}
428428

lightning-block-sync/src/poll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Validate for BlockHeaderData {
6161
fn validate(self, block_hash: BlockHash) -> BlockSourceResult<Self::T> {
6262
let pow_valid_block_hash = self.header
6363
.validate_pow(&self.header.target())
64-
.or_else(|e| Err(BlockSourceError::persistent(e)))?;
64+
.map_err(BlockSourceError::persistent)?;
6565

6666
if pow_valid_block_hash != block_hash {
6767
return Err(BlockSourceError::persistent("invalid block hash"));
@@ -82,7 +82,7 @@ impl Validate for BlockData {
8282

8383
let pow_valid_block_hash = header
8484
.validate_pow(&header.target())
85-
.or_else(|e| Err(BlockSourceError::persistent(e)))?;
85+
.map_err(BlockSourceError::persistent)?;
8686

8787
if pow_valid_block_hash != block_hash {
8888
return Err(BlockSourceError::persistent("invalid block hash"));

lightning-block-sync/src/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Blockchain {
106106
BlockHeaderData {
107107
chainwork: self.blocks[0].header.work() + Uint256::from_u64(height as u64).unwrap(),
108108
height: height as u32,
109-
header: self.blocks[height].header.clone(),
109+
header: self.blocks[height].header,
110110
}
111111
}
112112

@@ -162,7 +162,7 @@ impl BlockSource for Blockchain {
162162
}
163163

164164
if self.filtered_blocks {
165-
return Ok(BlockData::HeaderOnly(block.header.clone()));
165+
return Ok(BlockData::HeaderOnly(block.header));
166166
} else {
167167
return Ok(BlockData::FullBlock(block.clone()));
168168
}

lightning-invoice/src/de.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use core::num::ParseIntError;
66
use core::str;
77
use core::str::FromStr;
88

9-
use bech32;
109
use bech32::{u5, FromBase32};
1110

1211
use bitcoin_hashes::Hash;
@@ -18,7 +17,6 @@ use lightning::routing::router::{RouteHint, RouteHintHop};
1817

1918
use num_traits::{CheckedAdd, CheckedMul};
2019

21-
use secp256k1;
2220
use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
2321
use secp256k1::PublicKey;
2422

@@ -323,9 +321,9 @@ impl FromStr for RawHrp {
323321
};
324322

325323
Ok(RawHrp {
326-
currency: currency,
324+
currency,
327325
raw_amount: amount,
328-
si_prefix: si_prefix,
326+
si_prefix,
329327
})
330328
}
331329
}
@@ -342,7 +340,7 @@ impl FromBase32 for RawDataPart {
342340
let tagged = parse_tagged_parts(&data[7..])?;
343341

344342
Ok(RawDataPart {
345-
timestamp: timestamp,
343+
timestamp,
346344
tagged_fields: tagged,
347345
})
348346
}
@@ -515,7 +513,7 @@ impl FromBase32 for ExpiryTime {
515513

516514
fn from_base32(field_data: &[u5]) -> Result<ExpiryTime, ParseError> {
517515
match parse_int_be::<u64, u5>(field_data, 32)
518-
.map(|t| ExpiryTime::from_seconds(t))
516+
.map(ExpiryTime::from_seconds)
519517
{
520518
Some(t) => Ok(t),
521519
None => Err(ParseError::IntegerOverflowError),
@@ -540,7 +538,7 @@ impl FromBase32 for Fallback {
540538
type Err = ParseError;
541539

542540
fn from_base32(field_data: &[u5]) -> Result<Fallback, ParseError> {
543-
if field_data.len() < 1 {
541+
if field_data.is_empty() {
544542
return Err(ParseError::UnexpectedEndOfTaggedFields);
545543
}
546544

@@ -554,7 +552,7 @@ impl FromBase32 for Fallback {
554552
}
555553

556554
Ok(Fallback::SegWitProgram {
557-
version: version,
555+
version,
558556
program: bytes
559557
})
560558
},

lightning-invoice/src/lib.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,13 @@ impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBuilder<D, H, tb
585585
}).collect::<Vec<_>>();
586586

587587
let data = RawDataPart {
588-
timestamp: timestamp,
589-
tagged_fields: tagged_fields,
588+
timestamp,
589+
tagged_fields,
590590
};
591591

592592
Ok(RawInvoice {
593-
hrp: hrp,
594-
data: data,
593+
hrp,
594+
data,
595595
})
596596
}
597597
}
@@ -781,7 +781,7 @@ impl SignedRawInvoice {
781781
recovered_pub_key = Some(recovered);
782782
}
783783

784-
let pub_key = included_pub_key.or_else(|| recovered_pub_key.as_ref())
784+
let pub_key = included_pub_key.or(recovered_pub_key.as_ref())
785785
.expect("One is always present");
786786

787787
let hash = Message::from_slice(&self.hash[..])
@@ -1014,9 +1014,9 @@ impl PositiveTimestamp {
10141014
}
10151015

10161016
#[cfg(feature = "std")]
1017-
impl Into<SystemTime> for PositiveTimestamp {
1018-
fn into(self) -> SystemTime {
1019-
SystemTime::UNIX_EPOCH + self.0
1017+
impl From<PositiveTimestamp> for SystemTime {
1018+
fn from(val: PositiveTimestamp) -> Self {
1019+
SystemTime::UNIX_EPOCH + val.0
10201020
}
10211021
}
10221022

@@ -1147,7 +1147,7 @@ impl Invoice {
11471147
/// ```
11481148
pub fn from_signed(signed_invoice: SignedRawInvoice) -> Result<Self, SemanticError> {
11491149
let invoice = Invoice {
1150-
signed_invoice: signed_invoice,
1150+
signed_invoice,
11511151
};
11521152
invoice.check_field_counts()?;
11531153
invoice.check_feature_bits()?;
@@ -1185,9 +1185,9 @@ impl Invoice {
11851185
///
11861186
/// (C-not exported) because we don't yet export InvoiceDescription
11871187
pub fn description(&self) -> InvoiceDescription {
1188-
if let Some(ref direct) = self.signed_invoice.description() {
1188+
if let Some(direct) = self.signed_invoice.description() {
11891189
return InvoiceDescription::Direct(direct);
1190-
} else if let Some(ref hash) = self.signed_invoice.description_hash() {
1190+
} else if let Some(hash) = self.signed_invoice.description_hash() {
11911191
return InvoiceDescription::Hash(hash);
11921192
}
11931193
unreachable!("ensured by constructor");
@@ -1332,9 +1332,9 @@ impl Description {
13321332
}
13331333
}
13341334

1335-
impl Into<String> for Description {
1336-
fn into(self) -> String {
1337-
self.into_inner()
1335+
impl From<Description> for String {
1336+
fn from(val: Description) -> Self {
1337+
val.into_inner()
13381338
}
13391339
}
13401340

@@ -1398,9 +1398,9 @@ impl PrivateRoute {
13981398
}
13991399
}
14001400

1401-
impl Into<RouteHint> for PrivateRoute {
1402-
fn into(self) -> RouteHint {
1403-
self.into_inner()
1401+
impl From<PrivateRoute> for RouteHint {
1402+
fn from(val: PrivateRoute) -> Self {
1403+
val.into_inner()
14041404
}
14051405
}
14061406

@@ -1766,7 +1766,7 @@ mod test {
17661766

17671767
// Multiple payment secrets
17681768
let invoice = {
1769-
let mut invoice = invoice_template.clone();
1769+
let mut invoice = invoice_template;
17701770
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
17711771
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
17721772
invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
@@ -1792,7 +1792,7 @@ mod test {
17921792
assert_eq!(invoice.hrp.raw_amount, Some(15));
17931793

17941794

1795-
let invoice = builder.clone()
1795+
let invoice = builder
17961796
.amount_milli_satoshis(150)
17971797
.build_raw()
17981798
.unwrap();
@@ -1846,7 +1846,7 @@ mod test {
18461846
.build_raw();
18471847
assert_eq!(long_route_res, Err(CreationError::RouteTooLong));
18481848

1849-
let sign_error_res = builder.clone()
1849+
let sign_error_res = builder
18501850
.description("Test".into())
18511851
.payment_secret(PaymentSecret([0; 32]))
18521852
.try_build_signed(|_| {
@@ -1876,7 +1876,7 @@ mod test {
18761876

18771877
let route_1 = RouteHint(vec![
18781878
RouteHintHop {
1879-
src_node_id: public_key.clone(),
1879+
src_node_id: public_key,
18801880
short_channel_id: de::parse_int_be(&[123; 8], 256).expect("short chan ID slice too big?"),
18811881
fees: RoutingFees {
18821882
base_msat: 2,
@@ -1887,7 +1887,7 @@ mod test {
18871887
htlc_maximum_msat: None,
18881888
},
18891889
RouteHintHop {
1890-
src_node_id: public_key.clone(),
1890+
src_node_id: public_key,
18911891
short_channel_id: de::parse_int_be(&[42; 8], 256).expect("short chan ID slice too big?"),
18921892
fees: RoutingFees {
18931893
base_msat: 3,
@@ -1901,7 +1901,7 @@ mod test {
19011901

19021902
let route_2 = RouteHint(vec![
19031903
RouteHintHop {
1904-
src_node_id: public_key.clone(),
1904+
src_node_id: public_key,
19051905
short_channel_id: 0,
19061906
fees: RoutingFees {
19071907
base_msat: 4,
@@ -1912,7 +1912,7 @@ mod test {
19121912
htlc_maximum_msat: None,
19131913
},
19141914
RouteHintHop {
1915-
src_node_id: public_key.clone(),
1915+
src_node_id: public_key,
19161916
short_channel_id: de::parse_int_be(&[1; 8], 256).expect("short chan ID slice too big?"),
19171917
fees: RoutingFees {
19181918
base_msat: 5,
@@ -1927,7 +1927,7 @@ mod test {
19271927
let builder = InvoiceBuilder::new(Currency::BitcoinTestnet)
19281928
.amount_milli_satoshis(123)
19291929
.duration_since_epoch(Duration::from_secs(1234567))
1930-
.payee_pub_key(public_key.clone())
1930+
.payee_pub_key(public_key)
19311931
.expiry_time(Duration::from_secs(54321))
19321932
.min_final_cltv_expiry_delta(144)
19331933
.fallback(Fallback::PubKeyHash([0;20]))

lightning-invoice/src/payment.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ fn pay_invoice_using_amount<P: Deref>(
144144
invoice: &Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry,
145145
payer: P
146146
) -> Result<(), PaymentError> where P::Target: Payer {
147-
let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
148-
let payment_secret = Some(invoice.payment_secret().clone());
147+
let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
148+
let payment_secret = Some(*invoice.payment_secret());
149149
let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
150150
invoice.min_final_cltv_expiry_delta() as u32)
151-
.with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs())
151+
.with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
152152
.with_route_hints(invoice.route_hints());
153153
if let Some(features) = invoice.features() {
154154
payment_params = payment_params.with_features(features.clone());
@@ -203,7 +203,7 @@ where
203203
payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
204204
) -> Result<(), PaymentError> {
205205
self.send_payment_with_retry(payment_hash, payment_secret, payment_id, route_params, retry_strategy)
206-
.map_err(|e| PaymentError::Sending(e))
206+
.map_err(PaymentError::Sending)
207207
}
208208
}
209209

@@ -344,7 +344,7 @@ mod tests {
344344
let invoice = invoice(payment_preimage);
345345
let amt_msat = 10_000;
346346

347-
match pay_zero_value_invoice(&invoice, amt_msat, Retry::Attempts(0), &nodes[0].node) {
347+
match pay_zero_value_invoice(&invoice, amt_msat, Retry::Attempts(0), nodes[0].node) {
348348
Err(PaymentError::Invoice("amount unexpected")) => {},
349349
_ => panic!()
350350
}

0 commit comments

Comments
 (0)