Skip to content

Commit 1122e82

Browse files
authored
Merge pull request #3238 from Mirebella/clippy-checks
Added clippy ignore rules for all errors and warnings
2 parents bf6a53e + 0d71a5f commit 1122e82

File tree

21 files changed

+130
-45
lines changed

21 files changed

+130
-45
lines changed

.github/workflows/build.yml

+89-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,95 @@ jobs:
251251
rustup component add clippy
252252
- name: Run default clippy linting
253253
run: |
254-
cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err
254+
RUSTFLAGS='-D warnings' cargo clippy -- \
255+
`# Errors` \
256+
-A clippy::erasing_op \
257+
-A clippy::never_loop \
258+
`# Warnings` \
259+
-A renamed_and_removed_lints \
260+
-A clippy::blocks_in_conditions \
261+
-A clippy::borrow_deref_ref \
262+
-A clippy::clone_on_copy \
263+
-A clippy::collapsible_else_if \
264+
-A clippy::collapsible_if \
265+
-A clippy::collapsible_match \
266+
-A clippy::comparison_chain \
267+
-A clippy::doc_lazy_continuation \
268+
-A clippy::drain_collect \
269+
-A clippy::drop_non_drop \
270+
-A clippy::enum_variant_names \
271+
-A clippy::explicit_auto_deref \
272+
-A clippy::extra_unused_lifetimes \
273+
-A clippy::for_kv_map \
274+
-A clippy::from_over_into \
275+
-A clippy::get_first \
276+
-A clippy::identity_op \
277+
-A clippy::if_same_then_else \
278+
-A clippy::inconsistent_digit_grouping \
279+
-A clippy::iter_kv_map \
280+
-A clippy::iter_skip_next \
281+
-A clippy::large_enum_variant \
282+
-A clippy::legacy_numeric_constants \
283+
-A clippy::len_without_is_empty \
284+
-A clippy::len_zero \
285+
-A clippy::let_and_return \
286+
-A clippy::manual_filter \
287+
-A clippy::manual_map \
288+
-A clippy::manual_memcpy \
289+
-A clippy::manual_range_contains \
290+
-A clippy::manual_range_patterns \
291+
-A clippy::manual_saturating_arithmetic \
292+
-A clippy::manual_strip \
293+
-A clippy::map_clone \
294+
-A clippy::map_flatten \
295+
-A clippy::match_like_matches_macro \
296+
-A clippy::match_ref_pats \
297+
-A clippy::multiple_bound_locations \
298+
-A clippy::mut_mutex_lock \
299+
-A clippy::needless_bool \
300+
-A clippy::needless_borrow \
301+
-A clippy::needless_borrowed_reference \
302+
-A clippy::needless_borrows_for_generic_args \
303+
-A clippy::needless_lifetimes \
304+
-A clippy::needless_question_mark \
305+
-A clippy::needless_range_loop \
306+
-A clippy::needless_return \
307+
-A clippy::new_without_default \
308+
-A clippy::non_minimal_cfg \
309+
-A clippy::op_ref \
310+
-A clippy::option_as_ref_deref \
311+
-A clippy::option_map_or_none \
312+
-A clippy::option_map_unit_fn \
313+
-A clippy::precedence \
314+
-A clippy::ptr_arg \
315+
-A clippy::question_mark \
316+
-A clippy::readonly_write_lock \
317+
-A clippy::redundant_closure \
318+
-A clippy::redundant_field_names \
319+
-A clippy::redundant_guards \
320+
-A clippy::redundant_pattern_matching \
321+
-A clippy::redundant_slicing \
322+
-A clippy::redundant_static_lifetimes \
323+
-A clippy::result_large_err \
324+
-A clippy::result_unit_err \
325+
-A clippy::search_is_some \
326+
-A clippy::single_char_pattern \
327+
-A clippy::single_match \
328+
-A clippy::slow_vector_initialization \
329+
-A clippy::tabs_in_doc_comments \
330+
-A clippy::to_string_in_format_args \
331+
-A clippy::too_many_arguments \
332+
-A clippy::toplevel_ref_arg \
333+
-A clippy::type_complexity \
334+
-A clippy::unnecessary_cast \
335+
-A clippy::unnecessary_get_then_check \
336+
-A clippy::unnecessary_lazy_evaluations \
337+
-A clippy::unnecessary_mut_passed \
338+
-A clippy::unnecessary_sort_by \
339+
-A clippy::unnecessary_to_owned \
340+
-A clippy::unnecessary_unwrap \
341+
-A clippy::unused_unit \
342+
-A clippy::useless_conversion
255343
256344
rustfmt:
257345
runs-on: ubuntu-latest

lightning-rapid-gossip-sync/src/processing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ where
176176
.and_then(|node| node.announcement_info.as_ref())
177177
.map(|info| {
178178
synthetic_node_announcement.features = info.features().clone();
179-
synthetic_node_announcement.rgb = info.rgb().clone();
179+
synthetic_node_announcement.rgb.clone_from(&info.rgb());
180180
synthetic_node_announcement.alias = info.alias().clone();
181181
synthetic_node_announcement.addresses = info.addresses().to_vec();
182182
});

lightning/src/chain/onchaintx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
761761
for outpoint in req.outpoints() {
762762
log_info!(logger, " Outpoint {}", outpoint);
763763
}
764-
self.locktimed_packages.entry(package_locktime).or_insert(Vec::new()).push(req);
764+
self.locktimed_packages.entry(package_locktime).or_default().push(req);
765765
continue;
766766
}
767767

lightning/src/chain/package.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,7 @@ impl PackageTemplate {
10331033

10341034
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, soonest_conf_deadline: u32, height_original: u32) -> Self {
10351035
let (malleability, aggregable) = PackageSolvingData::map_output_type_flags(&input_solving_data);
1036-
let mut inputs = Vec::with_capacity(1);
1037-
inputs.push((BitcoinOutPoint { txid, vout }, input_solving_data));
1036+
let inputs = vec![(BitcoinOutPoint { txid, vout }, input_solving_data)];
10381037
PackageTemplate {
10391038
inputs,
10401039
malleability,

lightning/src/crypto/chacha20.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ mod real_chacha {
176176
) {
177177
let block = ChaCha20::get_single_block(key, nonce);
178178
for i in 0..bytes.len() {
179-
bytes[i] = block[i] ^ bytes[i];
179+
bytes[i] ^= block[i];
180180
}
181181
}
182182

lightning/src/crypto/chacha20poly1305rfc.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod real_chachapoly {
5959

6060
pub fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) {
6161
assert!(input.len() == output.len());
62-
assert!(self.finished == false);
62+
assert!(!self.finished);
6363
self.cipher.process(input, output);
6464
self.data_len += input.len();
6565
self.mac.input(output);
@@ -78,7 +78,7 @@ mod real_chachapoly {
7878
// Encrypt `input_output` in-place. To finish and calculate the tag, use `finish_and_get_tag`
7979
// below.
8080
pub(in super::super) fn encrypt_in_place(&mut self, input_output: &mut [u8]) {
81-
debug_assert!(self.finished == false);
81+
debug_assert!(!self.finished);
8282
self.cipher.process_in_place(input_output);
8383
self.data_len += input_output.len();
8484
self.mac.input(input_output);
@@ -87,7 +87,7 @@ mod real_chachapoly {
8787
// If we were previously encrypting with `encrypt_in_place`, this method can be used to finish
8888
// encrypting and calculate the tag.
8989
pub(in super::super) fn finish_and_get_tag(&mut self, out_tag: &mut [u8]) {
90-
debug_assert!(self.finished == false);
90+
debug_assert!(!self.finished);
9191
ChaCha20Poly1305RFC::pad_mac_16(&mut self.mac, self.data_len);
9292
self.finished = true;
9393
self.mac.input(&self.aad_len.to_le_bytes());
@@ -100,7 +100,7 @@ mod real_chachapoly {
100100
/// this decryption is *variable time*.
101101
pub fn variable_time_decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> Result<(), ()> {
102102
assert!(input.len() == output.len());
103-
assert!(self.finished == false);
103+
assert!(!self.finished);
104104

105105
self.finished = true;
106106

@@ -131,7 +131,7 @@ mod real_chachapoly {
131131
///
132132
/// Should never be `pub` because the public API should always enforce tag checking.
133133
pub(in super::super) fn decrypt_in_place(&mut self, input_output: &mut [u8]) {
134-
debug_assert!(self.finished == false);
134+
debug_assert!(!self.finished);
135135
self.mac.input(input_output);
136136
self.data_len += input_output.len();
137137
self.cipher.process_in_place(input_output);
@@ -140,7 +140,7 @@ mod real_chachapoly {
140140
/// If we were previously decrypting with `just_decrypt_in_place`, this method must be used
141141
/// to check the tag. Returns whether or not the tag is valid.
142142
pub(in super::super) fn finish_and_check_tag(&mut self, tag: &[u8]) -> bool {
143-
debug_assert!(self.finished == false);
143+
debug_assert!(!self.finished);
144144
self.finished = true;
145145
ChaCha20Poly1305RFC::pad_mac_16(&mut self.mac, self.data_len);
146146
self.mac.input(&self.aad_len.to_le_bytes());

lightning/src/crypto/poly1305.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl Poly1305 {
8282
d2 += c as u64; c = (d2 >> 26) as u32; h2 = d2 as u32 & 0x3ffffff;
8383
d3 += c as u64; c = (d3 >> 26) as u32; h3 = d3 as u32 & 0x3ffffff;
8484
d4 += c as u64; c = (d4 >> 26) as u32; h4 = d4 as u32 & 0x3ffffff;
85-
h0 += c * 5; c = h0 >> 26; h0 = h0 & 0x3ffffff;
85+
h0 += c * 5; c = h0 >> 26; h0 &= 0x3ffffff;
8686
h1 += c;
8787

8888
self.h[0] = h0;
@@ -111,11 +111,11 @@ impl Poly1305 {
111111
let mut h4 = self.h[4];
112112

113113
let mut c : u32;
114-
c = h1 >> 26; h1 = h1 & 0x3ffffff;
115-
h2 += c; c = h2 >> 26; h2 = h2 & 0x3ffffff;
116-
h3 += c; c = h3 >> 26; h3 = h3 & 0x3ffffff;
117-
h4 += c; c = h4 >> 26; h4 = h4 & 0x3ffffff;
118-
h0 += c * 5; c = h0 >> 26; h0 = h0 & 0x3ffffff;
114+
c = h1 >> 26; h1 &= 0x3ffffff;
115+
h2 += c; c = h2 >> 26; h2 &= 0x3ffffff;
116+
h3 += c; c = h3 >> 26; h3 &= 0x3ffffff;
117+
h4 += c; c = h4 >> 26; h4 &= 0x3ffffff;
118+
h0 += c * 5; c = h0 >> 26; h0 &= 0x3ffffff;
119119
h1 += c;
120120

121121
// compute h + -p

lightning/src/events/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ pub enum Event {
12711271
///
12721272
/// This field will be `None` for objects serialized prior to LDK 0.0.117.
12731273
channel_capacity_sats: Option<u64>,
1274+
12741275
/// The original channel funding TXO; this helps checking for the existence and confirmation
12751276
/// status of the closing tx.
12761277
/// Note that for instances serialized in v0.0.119 or prior this will be missing (None).
@@ -2049,7 +2050,7 @@ impl MaybeReadable for Event {
20492050
payment_hash,
20502051
purpose: _init_tlv_based_struct_field!(purpose, upgradable_required),
20512052
amount_msat,
2052-
htlcs: htlcs.unwrap_or(vec![]),
2053+
htlcs: htlcs.unwrap_or_default(),
20532054
sender_intended_total_msat,
20542055
onion_fields,
20552056
}))

lightning/src/ln/chan_utils.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,12 @@ pub fn build_commitment_secret(commitment_seed: &[u8; 32], idx: u64) -> [u8; 32]
221221
/// Build a closing transaction
222222
pub fn build_closing_transaction(to_holder_value_sat: Amount, to_counterparty_value_sat: Amount, to_holder_script: ScriptBuf, to_counterparty_script: ScriptBuf, funding_outpoint: OutPoint) -> Transaction {
223223
let txins = {
224-
let mut ins: Vec<TxIn> = Vec::new();
225-
ins.push(TxIn {
224+
let ins: Vec<TxIn> = vec![TxIn {
226225
previous_output: funding_outpoint,
227226
script_sig: ScriptBuf::new(),
228227
sequence: Sequence::MAX,
229228
witness: Witness::new(),
230-
});
229+
}];
231230
ins
232231
};
233232

@@ -702,8 +701,7 @@ pub(crate) fn make_funding_redeemscript_from_slices(broadcaster_funding_key: &[u
702701
/// Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
703702
/// commitment transaction).
704703
pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, contest_delay: u16, htlc: &HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures, broadcaster_delayed_payment_key: &DelayedPaymentKey, revocation_key: &RevocationKey) -> Transaction {
705-
let mut txins: Vec<TxIn> = Vec::new();
706-
txins.push(build_htlc_input(commitment_txid, htlc, channel_type_features));
704+
let txins= vec![build_htlc_input(commitment_txid, htlc, channel_type_features)];
707705

708706
let mut txouts: Vec<TxOut> = Vec::new();
709707
txouts.push(build_htlc_output(
@@ -1590,14 +1588,13 @@ impl CommitmentTransaction {
15901588
commitment_transaction_number_obscure_factor ^ (INITIAL_COMMITMENT_NUMBER - commitment_number);
15911589

15921590
let txins = {
1593-
let mut ins: Vec<TxIn> = Vec::new();
1594-
ins.push(TxIn {
1591+
let ins: Vec<TxIn> = vec![TxIn {
15951592
previous_output: channel_parameters.funding_outpoint(),
15961593
script_sig: ScriptBuf::new(),
15971594
sequence: Sequence(((0x80 as u32) << 8 * 3)
15981595
| ((obscured_commitment_transaction_number >> 3 * 8) as u32)),
15991596
witness: Witness::new(),
1600-
});
1597+
}];
16011598
ins
16021599
};
16031600
(obscured_commitment_transaction_number, txins)

lightning/src/ln/channel.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ impl ChannelState {
610610
}
611611
}
612612

613-
fn to_u32(&self) -> u32 {
613+
fn to_u32(self) -> u32 {
614614
match self {
615615
ChannelState::NegotiatingFunding(flags) => flags.0,
616616
ChannelState::FundingNegotiated => state_flags::FUNDING_NEGOTIATED,
@@ -9512,7 +9512,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
95129512
monitor_pending_forwards,
95139513
monitor_pending_failures,
95149514
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
9515-
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or(Vec::new()),
9515+
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
95169516

95179517
signer_pending_revoke_and_ack: false,
95189518
signer_pending_commitment_update: false,

lightning/src/ln/channelmanager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5163,7 +5163,7 @@ where
51635163
failure_code: fail_malformed_htlc.failure_code,
51645164
},
51655165
};
5166-
self.forward_htlcs.lock().unwrap().entry(incoming_scid).or_insert(vec![]).push(failure);
5166+
self.forward_htlcs.lock().unwrap().entry(incoming_scid).or_default().push(failure);
51675167
self.pending_events.lock().unwrap().push_back((events::Event::HTLCHandlingFailed {
51685168
prev_channel_id: incoming_channel_id,
51695169
failed_next_destination: htlc_destination,
@@ -6768,7 +6768,7 @@ where
67686768

67696769
peer_state.actions_blocking_raa_monitor_updates
67706770
.entry(prev_hop.channel_id)
6771-
.or_insert_with(Vec::new)
6771+
.or_default()
67726772
.push(raa_blocker);
67736773
} else {
67746774
debug_assert!(false,

lightning/src/ln/peer_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
14311431
let peer = &mut *peer_lock;
14321432
let mut msg_to_handle = None;
14331433
if peer_node_id.is_none() {
1434-
peer_node_id = peer.their_node_id.clone();
1434+
peer_node_id.clone_from(&peer.their_node_id);
14351435
}
14361436

14371437
assert!(peer.pending_read_buffer.len() > 0);

lightning/src/offers/invoice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ impl InvoiceContents {
10181018
self.fields().fallbacks
10191019
.as_ref()
10201020
.map(|fallbacks| filter_fallbacks(self.chain(), fallbacks))
1021-
.unwrap_or_else(Vec::new)
1021+
.unwrap_or_default()
10221022
}
10231023

10241024
fn features(&self) -> &Bolt12InvoiceFeatures {

lightning/src/offers/offer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ pub enum Quantity {
10481048
}
10491049

10501050
impl Quantity {
1051-
fn to_tlv_record(&self) -> Option<u64> {
1051+
fn to_tlv_record(self) -> Option<u64> {
10521052
match self {
10531053
Quantity::Bounded(n) => Some(n.get()),
10541054
Quantity::Unbounded => Some(0),

lightning/src/offers/signer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl MetadataMaterial {
240240
self.hmac.input(DERIVED_METADATA_HMAC_INPUT);
241241
self.maybe_include_encrypted_payment_id();
242242

243-
let mut bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or(vec![]);
243+
let mut bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or_default();
244244
bytes.extend_from_slice(self.nonce.as_slice());
245245
bytes.extend_from_slice(Hmac::from_engine(self.hmac).as_byte_array());
246246
bytes
@@ -256,7 +256,7 @@ impl MetadataMaterial {
256256
self.hmac.input(DERIVED_METADATA_AND_KEYS_HMAC_INPUT);
257257
self.maybe_include_encrypted_payment_id();
258258

259-
let bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or(vec![]);
259+
let bytes = self.encrypted_payment_id.map(|id| id.to_vec()).unwrap_or_default();
260260

261261
let hmac = Hmac::from_engine(self.hmac);
262262
let privkey = SecretKey::from_slice(hmac.as_byte_array()).unwrap();

lightning/src/routing/gossip.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,10 @@ where U::Target: UtxoLookup, L::Target: Logger
509509
let mut one_to_two_announcement: Option<msgs::ChannelUpdate> = None;
510510
let mut two_to_one_announcement: Option<msgs::ChannelUpdate> = None;
511511
if let Some(one_to_two) = chan.one_to_two.as_ref() {
512-
one_to_two_announcement = one_to_two.last_update_message.clone();
512+
one_to_two_announcement.clone_from(&one_to_two.last_update_message);
513513
}
514514
if let Some(two_to_one) = chan.two_to_one.as_ref() {
515-
two_to_one_announcement = two_to_one.last_update_message.clone();
515+
two_to_one_announcement.clone_from(&two_to_one.last_update_message);
516516
}
517517
return Some((chan_announcement, one_to_two_announcement, two_to_one_announcement));
518518
} else {

lightning/src/routing/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ where L::Target: Logger {
17041704
.filter(|(p, _)| p.blinded_hops().len() == 1)
17051705
.any(|(_, iter_info_opt)| iter_info_opt.is_some() && iter_info_opt != info_opt)
17061706
{
1707-
return Err(LightningError{err: format!("1-hop blinded paths must all have matching introduction node ids"), action: ErrorAction::IgnoreError});
1707+
return Err(LightningError{err: "1-hop blinded paths must all have matching introduction node ids".to_string(), action: ErrorAction::IgnoreError});
17081708
}
17091709
}
17101710
}

lightning/src/routing/scoring.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ mod bucketed_history {
15871587
}
15881588

15891589
impl LegacyHistoricalBucketRangeTracker {
1590-
pub(crate) fn into_current(&self) -> HistoricalBucketRangeTracker {
1590+
pub(crate) fn into_current(self) -> HistoricalBucketRangeTracker {
15911591
let mut buckets = [0; 32];
15921592
for (idx, legacy_bucket) in self.buckets.iter().enumerate() {
15931593
let mut new_val = *legacy_bucket;

lightning/src/routing/utxo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,9 @@ impl PendingChecks {
512512
if let Some(msg) = full_msg { ChannelAnnouncement::Full(msg.clone()) }
513513
else { ChannelAnnouncement::Unsigned(msg.clone()) });
514514
pending_checks.nodes.entry(msg.node_id_1)
515-
.or_insert(Vec::new()).push(Arc::downgrade(&future.state));
515+
.or_default().push(Arc::downgrade(&future.state));
516516
pending_checks.nodes.entry(msg.node_id_2)
517-
.or_insert(Vec::new()).push(Arc::downgrade(&future.state));
517+
.or_default().push(Arc::downgrade(&future.state));
518518
Err(LightningError {
519519
err: "Channel being checked async".to_owned(),
520520
action: ErrorAction::IgnoreAndLog(Level::Gossip),

0 commit comments

Comments
 (0)